/r/AskComputerScience

Photograph via snooOG

Ask Computer Science Questions And Get Answers! This subreddit is intended for questions about topics that might be taught by a computer science department at a university.

Ask Computer Science Questions And Get Answers!

Before posting please read our rules.

This subreddit is intended for questions about topics that might be taught by a computer science department at a university. Questions do not have to be expert-level - it's perfectly fine to ask beginner questions. We all start somewhere. All we ask is that your questions be on-topic.

If you have questions that aren't directly about computer science, here are some other subreddits that can likely offer you more help:

If your post is off-topic, or violates one of our other rules, your post may be removed.

/r/AskComputerScience

84,885 Subscribers

3

Looking for literature on a problem similar to string similarity

Looking for prior research on the topic, string similarity is the closest I have found so far.

This is like a string similarity computation, but not quite. I am writing a simulation where each item has a true quality, but sorting is based off of perceived quality (true quality with noise and biases).
So if the scores are 100, 92 , 333, 71,4, the best sort would be

333,100,92,71, 4 which should get the best score

moving 333 down should be a big hit on the score, so

100,92, 333,71,4 would be worse, since 333 is so much bigger . third best

moving 100 wouldn't be nearly as bad

333,92,71,100,4 would give the second best score

Currently I am multiplying length from the of the string by the value, for example

333 * 5 + 100*4+92*3+71*2 + 4*1

Is there a name for this problem? Any pointers to prior research are appreciated Thank you

2 Comments
2024/11/08
23:23 UTC

1

Compilers [LR and LL parsing]

0

I was supposed to implement a stack machine code and I wrote a production and the code works. I am not able to understand if I have written a LL parser or an LR parser.

Can anyone take some time to help me with what I have written?

main:
  | commands EOF {()}    
  | EOF {()}
commands:
  | command SEMI commands { $1; $3 }
  | command SEMI  { $1 }
  | command SEMI command_prime commands { $1; $4 }
  | command SEMI command_prime { $1} 
  

command:
  | PUSH INT { 
push
 $2;  }
  | POP      { 
pop
 ();  }
  | ADD      { 
add
 ();  }
  | SUB      { 
sub
 ();  }
  | MUL      { 
mul
 ();  }
  | DIV      { 
div
 ();  }
  | SHOW     { 
show
 ();  }
  |  { 
failwith
 "Lexing 
error
" }

command_prime:
 | NEWLINE { 
clean
();}
0 Comments
2024/11/08
17:07 UTC

1

Why is the condition in the Quicksort Partition algorithm <= and not < ?

In the Algorithms textbook by Cormen (chapter 7.1), The Partition algorithm is

Partition(A,p,r)
x = A[r]
i = p-1
for j = p to r-1
    if A[j] <= x
        i = i+1
        exchange A[i] with A[j]
    exchange A[i+1] with A[r]
return i+1

Why is the condition in the Partition algorithm <= and not < ?

Quicksort(A,p,r)
if p<r
    q = Partition(A,,p,r)
    Quicksort(A,p,q-1)
    Quicksort(A,q+1,r)
8 Comments
2024/11/07
18:10 UTC

3

pumping lemma for context free language

so the L={a^nb^mc^(m+n)}, this is a context-free language, but first I using pumping lemma to prove, this is not, so for the first case i want to pick v=ab, and y = bbb, when i=2, isn't v^2 = abab, and not follow the format of language, so it's not context-free?

And i have another question, is proving not context-free i need to consider all possible case, if one case is failed, then it means it is not context-free language or if through all case and i found it has one case that i pumping and it's still in the language, and it proves that this language is context free, and can i pick v or x as ab or bc, i was really confused, thank you so much if you can provide the explaination.

2 Comments
2024/11/07
17:30 UTC

1

Circuit Simulator

I have created a logic circuit simulator. This was for a school project. The actual coding took me about 2.5 months. Coded in JavaScript using the p5.js library. I had taken a few courses a few years back on coding using this library. I would say I am decent in coding for a Year 13 student(age 17 from the UK).I primarily code in python and am better at it. I used Javascript since I found it easier to draw stuff at that time using JS. How hard would it be for me to build a circuit simulator where users an build electrical circuits using resistors, capacitors etc keeping into account I have about 3-4 months to build it and I'm willing to spend around 3-4 hrs per week just on the coding. What differences would there in my coding and what problems would I face?

2 Comments
2024/11/07
13:25 UTC

3

Making a 4 bit subtractor from a 4 bit adder

Hey guys, I'm using Logisim to create a 16 bit cpu and right now I'm making a 4 bit adder/subtractor. I've followed this picture but a problem I'm getting is that the carry is 1 for values that it should not be 1 for, like when both inputs are 0. How should I fix this?

3 Comments
2024/11/07
00:12 UTC

1

Recommendation Algorithm and Best DBMS

I am developing an app based on Spotify and song lyrics. Users will be able to share lyric cards and play songs on Spotify, etc. When a user creates an account, I plan to create a basic profile based on their Spotify statistics. My main concern is whether I should save posts on a graph database like Neo4j and get the kth neighborhood based on Spotify's recommended songs through their API or use a more advanced database like Cassandra and perform content-based filtering using Scala or a similar language. I am aware that this may have legal issues, but I want to do it anyway.

0 Comments
2024/11/06
10:29 UTC

15

How did you guys get so good at algorithms?

I really don't get how some people can just pick up algorithms like it's nothing

I'm in this algorithms and design class and its absolutely fucking me up. Trying to come up with recurrence relations, find out amortized costs using potential functions, and then needing to come up with a proof for everything too...

I can understand the algorithms like Knapsack and Bellman-Ford etc. when they're explained to me, but when it comes to deriving something original using these algorithms as a base, I'm just completely lost. Looking at our posted solutions to said problems as well just adds to my confusion. Maybe I just need more practice, but it just feels so damn defeating to constantly be losing at this

If anyone out there is nutty with algorithms and proofs, how did you guys get so good? How do you think? Are there any good resources out there for this ?

Sorry if this kind of post isn't welcome here, I just wanted to let out little bit of steam

21 Comments
2024/11/06
04:17 UTC

1

question about self attention in the paper "Hopfield Network is All You Need."

Hello, I'm having some difficulty with the paper "Hopfield Network is All You Need." I don’t understand a particular passage, and I’d be incredibly grateful to anyone who could help me make sense of it. The passage in question is here: "https://ml-jku.github.io/hopfield-layers/#update".

In this section, they refer to matrices WWW, which are projections of patterns into associative spaces. I don’t understand what that means. Likewise, I don’t really understand the concrete function of Equation 28 and Equation 30. For instance, I have a clear idea of what the update equation introduced earlier in the article does (it helps denoise a pattern), but here, for Equations 28 and 30, I don’t understand their purpose at all.

Thanks

0 Comments
2024/11/05
13:39 UTC

11

what is microcode and where is it located?

(Second-year CS major here) So, I’ve been looking into lower and lower level stuff recently, as I find it fascinating at how much stuff computers are doing under the hood. I’ve been told many times that machine code is the lowest level of abstraction in controlling the computer, but now I’m seeing that there is another layer of microcode beneath that, and that it can be updated. Where is the microcode stored and how can it be updated? Is the microcode the lowest level of abstraction for computers, or is there another level beneath that, or is machine code actually at the bottom of that hierarchy? Can programmers utilize microcode in their programs in the same way you can use assembly to have more control over their programs or to optimize them?

25 Comments
2024/11/05
05:23 UTC

9

Books about the history of computers.

Im trying to get into the history of computers. im looking for a book that goes into depth about the technologies and how they were made. i want to start at the beginning and work my way up to the present day.

8 Comments
2024/11/04
11:13 UTC

2

Why does 6502 Assembly not have any opcodes ending in 3, 7, B, or F, and only one ending in 2? (A2 - LDX $xx)

This greatly confuses me.

3 Comments
2024/11/04
06:42 UTC

2

In the context of computational complexity theory, how would Shor's algorithm impact the security of RSA encryption, and what are the potential cryptographic protocols that can be developed to ensure quantum-resistant security?

I have been thinking a lot about cryptography in the age of quantum computing. Would like some leads here to work off of and discuss. Note I am not a cs major but I am trying to pivot into cs,ml,ai and cybersecurity.

3 Comments
2024/11/04
01:19 UTC

2

Few questions on interpretation and evaluator ......

A program when is passed to the evaluator breaks it down to the simplest of instructions ... the primitive instructions... My question is does the primitive instruction directly get converted to the maschine code from there ? Like + is a primtive instrcution in a language so does the evaluator or the interpreter have a data structure storing these primitive instructions and thier respective maschine codes ..... or is it conversion happening at a later time ?

In normal order evaluation ... suppose i have defined a list of (1,2,3,4,(1 / 0)). Here the 5th element is an error.. so when I define the list and never use list[4] the program will run without an error or what ??

Ik in applicative order evaluation the moment u define it the evaluator program will evaluate the list and throw an error on the 5th element ... please correct me on this if I am wrong....

Any help would be appreciated. And sorry if this is the wrong sub ....

7 Comments
2024/11/03
21:26 UTC

1

2DFA to NFA conversion process - what is the method of finding the right-matches of all valid crossing sequences?

Hi all, this is my first time posting here.

I have a copy of Hopcroft and Ullman’s Introduction to Automata Theory, Languages, and Computation (1979), and am trying to understand the methodology for converting a two-way deterministic finite automaton (2DFA) into a one-way non-deterministic finite automaton (NFA).

I have just about managed to grasp the reasoning which defines left/right matching (using the recursive definition in the book on pg. 39), but don't understand how you go about "discovering" all the possible left/right-matches for a given crossing sequence on a particular symbol.

To use Example 2.16 from the book (pg. 41):

2DFA M = ({q0, q1, q2}, {0, 1}, 𝛿, q0, {q0, q1, q2}), with 𝛿 given by:

01
q0(q0, R)(q1, R)
q1(q1, R)(q2, L)
q2(q0, R)(q2, L)

Of all the valid crossing sequences that could exist for M, only four have the potential to manifest, given the transition function above (q0 and q1 can only be entered on R moves, and q2 only on L moves):

  • [q0]
  • [q1]
  • [q0, q2, q1]
  • [q1, q2, q0]

The example then lists these four sequences with their possible right-matching crossing sequences, on each of the symbols in the alphabet, like so:

Right-matches on 0Right-matches on 1
[q0][q0][q1]
[q1][q1], [q1, q2, q0]--
[q0, q2, q1]----
[q1, q2, q0]--[q1]

Now, I think I follow how the row for [q0] got its answers, and at least the [q1] and -- for the [q1] row, but I'm falling down at how the other values were deduced, and how you can be certain that all the matches for each of the rows have been explored and listed.

How do you discover that [q1] right-matches [q1, q2, q0] on 0?

How do you come to the conclusion for the values in the [q0, q2, q1] and [q1, q2, q0] rows?

Is the -- value here the same as the null/empty sequence []? I believe it is, but I'm second guessing myself now.

I don't have a background in pure mathematics, but do have a background in computer science, so apologies if I'm not using exact phraseology in my questions here!

0 Comments
2024/11/03
19:32 UTC

4

binary operators and sets

if we say that some operator is a binary operator to set S, does that necessarily mean that the set is closed relative to the operator?, the way the book talked about it seemed like both terms are referring to the same case.

6 Comments
2024/11/03
15:19 UTC

24

First time CS teacher (intro Java; high school) - chatgpt & cheating

Hi all, I'm a brand new, first year physics teacher who got surprised when I was told I'd also be teaching my high school's intro to CS (java) course. I'm doing my best, and I think things are mostly going well.

Midway through the course though, as concepts start to become more challenging for beginners, I stumbled on students who are almost assuredly using chatgpt on lab assignments (HW). I don't want to be all Boomer status... but how should I go about this? I would consider copying & pasting my assignment into chatgpt, then submitting the generated Java code cheating... but I also don't know how to broach the subject?

Any advice from experienced teachers out there? I know most of my students aren't ever going to need programming again afterwards, but I still want them to gain critical thinking & problem solving skills, logic & pattern recognition, etc. that you naturally develop during an Intro CS class, that I fear they'll miss out on if they plagiarize

26 Comments
2024/11/03
04:07 UTC

1

unsigned binary number subtraction by compliment

if we want to determine if the answer is positive or negative in our subtraction by compliments in unsigned binary numbers, it would be easy for us to see which is larger and quickly determine that but if we want to find a clue to make the computer understand when it's negative and when it's positive I suppose the answer is always positive if there's an end carry when we add the minuend to the compliment of the subtrahend, correct?
assuming M and N are two unsigned values, base r.

M - N = M - N + r^n - r^n = M + (r^n-N) - r^n

if M+(r^n-N) produces a sum that is less than r^n by a digit (which is the carry digit that's supposed to make the end subtraction result positive) the answer is negative by necessity. correct?

0 Comments
2024/11/02
23:40 UTC

5

OS and CPU Query

I was reading OS, and read only the following information -

If there are 2 process and one is currently being executed and second is ready. If current running process needs IO, OS will block it and set the CPU from user mode to kernel mode and OS will wait for IO. OS will then allow second process to run by CPU.

I’m dumb and wasn’t satisfied so did some ChatGPT conversations and found this-

Process1 when needs IO will make a system call, OS will switch the CPU from user mode to kernel mode and command CPU to trigger control signal to IO device. Once the command is sent by CPU. OS will turn CPU back to User mode from Kernel Mode and start Process2 and let CPU run it. When IO is ready it will trigger an interrupt to CPU, and CPU again moves from user mode to kernel mode on direction of OS and handle the input output

I mean either I’m literally dumb because I couldn’t understand it in few lines or the content is, I’ll like views, do all books teach the same first way, is there any which can treat me a little dumb?

And why is OS all the centre of attraction when CPU does all

4 Comments
2024/11/02
20:32 UTC

9

Main purpose of Search algorithms (Don't really have a good understanding) QUESTION

To find something you need to what what to look for. E.g. (to find an element in a list you need to know the element.). Why are search algorithms like binary or linear search (i know how they work) used? Why would you use them to find an element in a list when you already know the element? (Correct me if im wrong anywhere)

12 Comments
2024/11/02
16:05 UTC

1

question 2

is it ok to feel like an absolute brick while studying digital logic for the first time? I don't know if it's ok tbh but I've been studying it since yesterday and I feel kinda lost and need a lot of practice on paper, all of this is stemming from not wanting to memorize rules like some pattern to pass an exam, I'm trying to understand concepts and cement them to build on them when future concepts are presented, any advice or potential sources or learning tips would be appreciated.

morris mano's book is good so far, but I got a lot of questions and often re-read paragraphs multiple times to understand.

3 Comments
2024/11/02
14:25 UTC

5

Economic impact of different programming languages.

The potential of AI is often speculated to be the next Industrial Revolution. That might be true but in my own work I am finding much more primitive tools are driving massive increases in automation. My boss asked me to write a report on automation at work after I discovered 30% of my job could be described with a few dozen SQL queries and a bash script. I probably should have kept that a secret but instead I boasted about it like a fool. The rest of my job might also be possible to automate with two dozen API calls in Visual Basic. About 300 people have a job similar to my own at this company and it would obviously be a big deal if it can be automated. I have been pondering that mass layoffs would be a massive disincentive for automation but at the same time, it just seems so inevitable and straightforward that I might be the one to do it.

I’m wondering if this community knows about any academic work on the relative economic impact of different programming languages. Is C++ responsible for the most impact by virtue of being the most common or perhaps something archaic like BASIC has the most widespread and documented economic impact.

I’m also interested in anecdotal experiences of where you think the most high impact stuff is coming from. From my perspective Chat GPT is 1% as useful as SQL and Bash but maybe that’s just my particular industry.

2 Comments
2024/11/02
12:16 UTC

2

question

I'm currently taking a digital logic design course and I watched a video about overflowing cases in data, where you have (let's say) 4 bits of signed memory, now if you add two negative numbers like -7 and -4, you'll end up with an extra fifth digit that won't fit in the 4 bits, same as with the case when you add 7 and 1, you'll get 4 digits but representing the wrong value, -8

my question is, by that logic, does overflow refer to the occasion where you get an incorrect answer overall? considering in the second case there wasn't an extra fifth digit that won't fit in the 4 bits, -8 fits perfectly in 4 bits yet is the incorrect answer.

2 Comments
2024/10/31
15:11 UTC

7

Does an algorithm exist where we both cannot prove halting, and where meaningful output is produced?

Does there exist an algorithm that is both designed to halt, and produces meaningful output that is used for practical purposes, but one where we cannot definitively prove that it halts for all inputs? The closest algorithm I can think of is the Collatz conjecture, but it doesn't produce meaningful output. I am studying whether is is necessary to be able to test algorithms like Collatz, since they don't appear to have many practical applications. My best guess is that the algorithm would have something to do manipulating numbers in a loop based on conditions on them, like with the Collatz conjecture.

6 Comments
2024/10/30
18:15 UTC

1

Natural Deduction

I'm trying to solve this: (A ∧ B) → C ⊢ A → (B → C)

And I wonder if that's what I came up with is correct. Is it possible to start with the A ∧ B assumption?

  1. (A ∧ B) → C

  1. A ∧ B (assumption)

  2. A ∧ E(2)

  3. B ∧ E(2)

  4. C → E(1,2)

  5. B → C → I(4,5)


  1. A → (B → C) → I(3,6)

Is it correct?

Solution starts with assumptions A and then B to form A ∧ B.

4 Comments
2024/10/29
15:20 UTC

1

Pub Sub & Streaming data

I have a pub sub (kafka) network which sends data from Machine A to machine B, now issue is its overloading the consumer which is causing my code and linux to crash..
Just wondering what the best pratice is here for pub sub related things, how can i make it into a concrete pipeline?
Do note i cannot use cloud for a pipeline, i have a network but not necessarily access to internet

4 Comments
2024/10/29
05:30 UTC

6

CPU clock cycle time question

Reading Computer Organization by Patterson and Hennessy and they mention that lowering the instruction count of a program may lead to an increase in clock cycle time. Therefore, improving performance isn’t as straightforward as lowering the instruction count. could someone explain how lowering the instruction count affects clock speed and why it would decrease it?

3 Comments
2024/10/29
01:21 UTC

1

Where can I find the primitive maschine instructions?

An + operation is represented by a binary code ....

Where can I find all these instructions and code representation for them???

12 Comments
2024/10/28
21:34 UTC

2

Program Counter in Logic Gates

My professor wants our class to make a 4 bit program counter out of logic gates on Digital Simulator but he didn't teach us how to use it. I know how it works but I don't know how to express it in logic gates.

Also the instructions don't have the jump in the program, just Load and Increment.

Didn't tell us anything else on how to do it. Please help.

Clarification: We're making a CPU in class but I only fully understand the wider scope and nothing about the logic gates inside.

I'm requesting any resources or any images that show the logic gates.

5 Comments
2024/10/28
11:48 UTC

8

How do I cover gaps in knowledge?

I regret not learning seriously

Hi folks, I hope you’re doing well.

I am a student currently studying Computer Science at university.

I studied very shallowly in the first 1/3rd of the curriculum.

I regret not taking everything seriously from the beginning because I have now become passionate and interested in computer science as a field beyond getting a qualification for a job.

In the first few modules I crammed and retained very little knowledge. I have been more diligent with my more recent work and plan on continuing to do so.

How can I overcome the knowledge gaps I created?

I am also working part time so going back to each of those subjects is going to be challenging.

How would you deal with this situation if you were me?

8 Comments
2024/10/28
10:20 UTC

Back To Top