/r/computerscience

Photograph via snooOG

The hot spot for CS on reddit.

Welcome to /r/ComputerScience!

We're glad you're here.

This subreddit is dedicated to discussion of Computer Science topics including algorithms, computation, theory of languages, theory of programming, some software engineering, AI, cryptography, information theory, and computer architecture.

Rules

  1. Content must be on-topic
  2. Be civil
  3. No career, major, or courses advice
  4. No advertising
  5. No joke submissions
  6. No laptop/desktop purchase advice
  7. No tech/programming support
  8. No homework, exams, projects etc.
  9. No asking for ideas

For more detailed descriptions of these rules, please visit the rules page

Related subreddits

Credits

  • Header image is found here.
  • Subreddit logo is under an open source license from lessonhacker.com, found here

NIGHT MODE NORMAL

/r/computerscience

419,416 Subscribers

2

Am I oversimplifying Machine Learning/Data Science

I'm an Actuary who has some exposure to applied Machine Learning (Mostly regressions, stochastic modeling, and GLMs), but I'm wondering if there's a huge gap in difficulty between Theory and practice.

As a bit of a background, I took a Machine Learning exam (Actuary Exam Predictive Analytics) several years back about GLMs, decision trees and K-means clustering, but that exam focused mainly on applying the techniques to a dataset. The study material sort of hand-waved the theoretical explanations, which makes sense since we're business people, not statisticians. I passed the exam with just a week of studying. For work, I use logistic regression and stochastic modeling with a lognormal distribution, both of which are easy if you ignore the theoretical parts.

So far, everything I've used and have been taught seems rather... erm... easy? Like I could pick it up a concept in 5 minutes. I spent like 2 minutes reading about GLMs (Had to use logistic regression for a work assignment), and if you're just focusing on the application and ignoring the theory, it's super easy. Like you learn about the Logit link function on the mean and that's about the most important part for application.

I'm not trying to demean data scientists, but I'm curious why they're being paid so much for something that can be picked up in minutes by someone who passed high school Algebra. Most Actuaries use models that only have very basic math, but the models have incredible amounts of interlinking parts on workbooks with 20+ tabs, so there's an prerequisite working memory requirement ("IQ floor") if you want to do the job competently.

What exactly do Data Scientists/ML engineers do in industry? Am I oversimplifying their job duties?

14 Comments
2024/12/02
14:54 UTC

1

When/What condition is A -> ε is accepted in context sensitive grammar?

To my knowledge context sensitive grammar must have the length of the right hand side equal or greater than the left hand side. ε has a length of zero so following by definition all right hand side that has the value of ε violates this rule but there are some exceptions. I understand how some of these exceptions work but there are only a limited amount of resources I could find about it.

1 Comment
2024/12/02
13:59 UTC

2

What are some subjects to explore?

I want to explore ideas and different subjects about computer science or interdisciplinary subjects. I know that the more you know the more you can connect ideas to form a new idea. So i want to know more. But i dont know what to look for. Also some people say look for topics you enjoy eeading but i don't have anything on my mind. How can i explore more knowledge too see what I'm interested in?

21 Comments
2024/12/02
11:13 UTC

3

Halting Problem Reductions and Feeding a machine its own input

So far I can comprehend on a surface level when reading the reductions proofs for example reducing the Halting Problem to the Halting problem on an Empty String. The only (important) thing I can’t really visualise in my head however hard I try in all of these kinds of proofs is

  1. How a machine is fed its own encoding as input.
  2. How a machine simulates another machine on an input.

I just can’t wrap my head around it. In the case of halting on an Empty string, the new machine M# ignores its own input, clears the tape, writes w onto its tape and then simulates the original machine M on w. What does it exactly mean to ignore its own input? What’s happening on the inside and what on the outside? If someone could visualise it that would be great.

3 Comments
2024/12/02
11:03 UTC

3

Confused with an explanation of a recurrence relation

I am confused with this recurrence given in Algorithms by Jeff Erickson:

T(n) = 2T(n/2) + n/logn

The explanation given for the depth of the tree is: “The sum of all the nodes in the ith level is n/(lg n−i). This implies that the depth of the tree is at most lg n−1.”

I can’t seem to relate the two. I understood how the level wise cost is n/(lg n-i), but can’t seem to figure out the latter. Would love some help/ explanation on this.

1 Comment
2024/12/02
10:27 UTC

9

Is prolog like “throw it all into z3”

I had a prolog class at university 35 years ago.

I vaguely remember that there were cases where it was all declarative and magically found the solution. And a lot of the time it got lost, and you had to goad it, and code got just as long, but less readable than doing it in FORTRAN.

Today, when having to solve a problem (e.g. Sudoku), you can either try to come up with a clever algorithm, or write 5 lines of python that dump it into z3.

This feels similar to what i remember of prolog. Are there technical similarities between prolog and sat solvers / constraint solvers?

2 Comments
2024/12/02
05:13 UTC

1

Need Help Confirming Address Space Size Calculations for Logical and Physical Addresses

Hi everyone,

I’ve been working on a problem involving address space sizes, and I want to confirm if my understanding and calculations are correct. Here’s the problem:

We’re given:

  1. A logical address space of 256 pages.
  2. A page size of 4 KiB (2¹² bytes).
  3. Physical memory consisting of 64 frames.

I’ve attempted the solution as follows:

Logical Address:

The number of pages in the logical address space is 256, so to represent 256 pages, we need:

Bits for Page Number = log₂(256) = 8 bits.

The page size is 4 KiB = 2¹² bytes.
To represent the byte offset within a page, we need:

Bits for Page Offset = log₂(2¹²) = 12 bits.

Total Logical Address Bits = Bits for Page Number + Bits for Page Offset = 8 + 12 = 20 bits.

Physical Address:

The number of frames in physical memory is 64.
To represent 64 frames, we need:

Bits for Frame Number = log₂(64) = 6 bits.

The frame size is the same as the page size (4 KiB = 2¹² bytes).
To represent the byte offset within a frame, we need:

Bits for Frame Offset = log₂(2¹²) = 12 bits.

Total Physical Address Bits = Bits for Frame Number + Bits for Frame Offset = 6 + 12 = 18 bits.

Can someone confirm if these calculations are correct, or let me know if I’ve misunderstood any part of the problem? I’d also appreciate any insights into alternative ways to think about address space size calculations if there’s a simpler approach.

Thanks in advance for your help! 😊

0 Comments
2024/12/01
23:02 UTC

0

In your perspective, what do you think we should put in a Letter of motivation/personal statement?

I mean, I mean, they ask you to talk about why are you interested in certain area or what do you spect to accomplish there... But my opinion is that it should show more of your personality and of your character. I wish someone could give me some advice about successful letters of motivation:(

6 Comments
2024/12/01
22:43 UTC

78

What are currently the hot topics in computer science research?

Question

36 Comments
2024/12/01
21:29 UTC

2

Computer Science GCSE student here

Exclaimer: This is not in a way me asking for advice about something to do with my course. I'm curious about something I did due to something my CS teacher said.

During one of my CS lessons, we were covering Binary search again (due to it being a weak spot in our exams) & my teacher jokingly said "For the coders In this room, I wonder if any of you will be able to code Binary Search in Python.". She then immediately retracted this statement because of how difficult it apparently is. I took this as a challenge & immediately jumped to coding it in between tasks. I finished it just as we were wrapping up the lesson & well, it worked perfectly. My teacher told me how she was impressed by me & that 'Coding Binary Search is a university level skill'.

Basically what I'm wondering is if coding Binary Search is actually that difficult. Python was the coding language I used.

14 Comments
2024/12/01
16:37 UTC

5

Need Help with Banker’s Algorithm: Minimal Resources for a Safe State

Hi everyone,

I’m working on a problem involving the Banker’s Algorithm, and I’m stuck on determining the smallest value of x for which the system is in a safe state. Here’s the problem setup:

Problem Description:

The system has 4 processes and 5 allocatable resources. The current allocation, maximum needs, and available resources are as follows:

ProcessAllocationMaxAvailable
P01 0 2 1 11 2 1 3 0 0 x 1 2
P12 0 1 1 02 2 1 0
P21 1 0 1 02 1 3 1 0
P31 1 1 1 01 2 2 2 1

Objective:

What is the smallest value of x such that this is a safe state?

Hints provided:

  1. Compute the "needs matrix" (Need=Max−Allocation).
  2. Identify the process that can complete first if x is sufficiently large.

I’ve calculated the needs matrix and tried different values for x, but I’m not entirely sure how to proceed with finding the exact smallest x that ensures the system remains in a safe state. I’d appreciate if someone could guide me through the steps or point me to resources that explain this process in detail.

Thanks in advance for your help!

What I’ve Tried So Far:

  • Calculated the needs matrix:
    • Need[i][j]=Max[i][j]-Allocation[i][j],
      • where i represents the process number, j represents the resource type. The Max matrix indicates the maximum demand of each resource for each process. The Allocation matrix indicates the resources currently allocated to each process.
    • For each process Pᵢ and each resource Rⱼ, subtract the allocated resources from the maximum demand:  
      • Need ᵢⱼ=Max ᵢⱼ−Allocation ᵢⱼ 

ProcessAllocation (A)Max (M)Need (M - A)
P0[1,0,2,1,1][1,1,2,1,3][0,1,0,0,2]
P1​[2,0,1,1,0][2,2,2,1,0][0,2,1,0,0]
P2​[1,1,0,1,0][2,1,3,1,0][1,0,3,0,0]
P3​[1,1,1,1,0][1,1,2,2,1][0,0,1,1,1]

Now, given the availability vector, we know that R₁=0, R₂=0, R₄=1, R₆=2 are fixed, but we want to determine R₃.

A process can execute if its resource requirements (from the Needs Matrix) are less than or equal to the resources currently available. For each process Pᵢ, we check if:  

Need[i][j] ≤ Available [j] ∀j   

Where:

− Need[i][j] is the need of process Pᵢ for resource Rⱼ.

− Available [j] is the current availability of resource Rⱼ.

If Need(P₀)=[0,1,0,0,2], then:

- For R₁: 0 ≤ 0 (satisfied)

- For R₂: 1 ≤ 0 (not satisfied, so P₀ cannot run yet),

- For R₃: 0 ≤ x (always satisfied because 0 ≤ x for any x ),

- For R₄: 0 ≤ 1 (satisfied),

- For R₅: 2 ≤ 2 (satisfied).

Since all conditions are not satisfied, do we state that P₀ cannot run? Do we repeat this calculation process for the other P's? But I am not sure how we get to the point of determining the smallest x.

Any help is appreciated!

1 Comment
2024/12/01
05:53 UTC

6

Resources for learning some new things?

I'm not interested in programming or business related readings. I'm looking for something to learn and read while I'm eating lunch or relaxing in bed.

Theory, discoveries, and research are all things I'd like to learn about. Just nothing that requires me to program to see results

6 Comments
2024/11/30
23:02 UTC

9

Looking for books/courses on interpreters/compilers

Hello,
I'm looking for a book or a course that teaches interpreters and/or compilers. So far, I have tried two books: Crafting Interpreters by Robert Nystrom and Writing an Interpreter in Go by Thorsten Ball.

The issue I have with the former is that it focuses too much on software design. The Visitor design pattern, which the author introduced in the parsing chapter, made me drop the book. I spent a few days trying to understand how everything worked but eventually got frustrated and started looking for other resources.

The issue with the latter is a lack of theory. Additionally, I believe the author didn't use the simplest parsing algorithm.

I dropped both books when I reached the parsing chapters, so I'd like something that explains parsers really well and uses simple code for implementation, without any fancy design patterns. Ideally, it would use the simplest parsing strategy, which I believe is top-down recursive descent.

To sum up, I want a book or course that guides me through the implementation of an interpreter/compiler and explains everything clearly, using the simplest possible implementation in code.

A friend of mine mentioned this course: Pikuma - Create a Programming Language & Compiler. Are any of you familiar with this course? Would you recommend it?

7 Comments
2024/11/30
19:09 UTC

48

Abstraction and Hierarchy in CS Learning

I’m struggling to adapt to the way abstraction is presented in computer science. It often feels like I’m expected to accept concepts without fully understanding their foundations. When I try to dive deeper into the “why” behind these abstractions, I realize how much foundational knowledge I lack. This leads to excessive research and falling behind in school.

Coming from a math background, this approach feels unnatural. Mathematics starts with axioms and builds an interconnected framework where everything can be traced back to its core principles. I understand that computer science isn’t mathematics, but I find myself wanting to deeply understand the theoretical and technical details behind decisions in CS, not just focus on practical applications.

I want to know your thoughts , if someone ever felt the same and how should I approach this with better mindset.

——— Edit:

I want to thank everyone for the thoughtful advice and insights shared here. Your responses have helped me rethink my mindset and approach to learning computer science.

What a truly beautiful community! I may not be able to thank each of you individually, but I deeply appreciate the guidance you’ve offered.

36 Comments
2024/11/30
13:35 UTC

4

Is there any way or any library to find the top researchers in a specific field of computer science?

I have searched for it quite a bit but havent found anything useful. For example i want to find the top researchers in machine learning, or in theoretical cryptography (they could be ranked by something simple like their citations).

10 Comments
2024/11/29
21:56 UTC

0

What's the difference between volumes, partitions, and containers?

I recently installed Veracrypt (an encryption program) and have been introduced to some file system terms such as volume, partition, and container. From what I understand, a volume is a logical storage area that may or may not be directly tied to a physical drive, a partition is a logical subdivision/region of a drive, and I have no idea what a container is. I also don't quite understand the difference between a volume and a partition, as both seem to be logical areas of storage. Any help would be much appreciated.

5 Comments
2024/11/29
13:00 UTC

1

Proof of the Fundamental Theorem of Algebra in a formalization system I am developing

∀p(z)(Polynomial(p(z)) ∧ deg(p(z)) > 0 → (∃c∈ℂ(Root(p(z), c)) ∧ ∀k(1 ≤ k ≤ deg(p(z)) → ∃c∈ℂ(RootMultiplicity(p(z), c, k)) ∧ TotalRoots(p(z)) = deg(p(z)))))

(Assume ¬∃c∈ℂ(Root(p(z), c))) → (∀z(∃s(|z| > s → |p(z)| > 2|p₀|)) ∧ ∃t(|p(t)| = min(|p(z)|, |z| ≤ s))) ∧ (Define q(z) = p(z + t)) ∧ (q(0) = q₀ = |p(t)|) ∧ (q(z) = q₀ + qₘzᵐ + ∑_{k>m} qₖzᵏ) ∧ (∃r(Choose z = r(-q₀/qₘ)^(1/m))) ∧ (q(z) = q₀ - q₀rᵐ + ∑_{k>m} qₖzᵏ) ∧ (|q(z)| < |q₀| due to geometric decay of ∑_{k>m} qₖzᵏ) ∧ (Contradiction |q(0)| = min(|q(z)|)) → ¬(¬∃c∈ℂ(Root(p(z), c))) → ∃c∈ℂ(Root(p(z), c)).

(∃c∈ℂ(Root(p(z), c))) → (∀p(z)(p(z) = (z - c)q(z) ∧ deg(q(z)) = deg(p(z)) - 1)) → (∀n(Induction(n ≥ 1 ∧ deg(p(z)) = n → p(z) has exactly n roots counting multiplicities))) → ∀p(z)(deg(p(z)) = n → TotalRoots(p(z)) = n).

13 Comments
2024/11/29
07:29 UTC

153

How is it possible for one person to create a complex system like Bitcoin?

I’ve always wondered how it was possible for Satoshi Nakamoto, the creator of Bitcoin, to develop such a complex system like Bitcoin on their own.

Bitcoin involves a combination of cryptography, distributed systems, economic incentives, peer-to-peer networking, consensus algorithms (like Proof of Work), and blockchain technology—not to mention advanced topics like hashing, digital signatures, and public-key cryptography. Given how intricate the system is, how could one individual be responsible for designing and implementing all of these different components?

I have a background in computer science and I’m an experienced developer, but I find the learning curve of understanding blockchain and Bitcoin's design to be quite complex. The ideas of decentralization, immutability, and the creation of a secure, distributed ledger are concepts I find fascinating, but also hard to wrap my head around when it comes to implementation. Was Satoshi working alone from the start, or were there contributions from others along the way? What prior knowledge and skills would one person need to be able to pull something like this off?

I’d appreciate any insights from those with deeper experience in the space, particularly in areas like cryptographic techniques, distributed consensus, and economic models behind cryptocurrencies.

Thanks!

104 Comments
2024/11/28
18:30 UTC

2

Does firewall blocks all packets OR blocks only the TCP connection from forming? Given that HTTP is bidirectional, why is there outbound setting and inbound setting?

4 Comments
2024/11/28
04:13 UTC

1

A thought on P = NP notion...

So today in my Theory of Computation class we were discussing P and NP problems. Our proff told us that "Is P=NP ?" a big question in computer science. Then we discussed the formal definitions for both (the one that says for NP there exists a verification algo which can verify a possible answer in polynomial time...). He said that there are many great computer scientists of our generation who belive that P = NP. He gave some philosophical notions also which argue that P should be equal to NP. During this disccusion I thought of a scenario in my mind which goes as below:

Let's say I am in an interview and I need to solve a problem. I give a solution which solves the problem in exponential time but the interviewer asks me to solve it in polynomial time. So I derive a solution which, when provided a possible answer to the problem, can VERIFY if it is right or wrong in polynomial time. So if P = NP then this should work and I should get the job (given that this problems is the only criteria).

Ofcourse in real life this sceniario is pretty trivial because ofcourse the interviewer will not accpet this and I will be reject.

So I just wanted to here thoughts of the community on this. My apologize if there is a blunder in my understandig of the concept :))

5 Comments
2024/11/26
17:02 UTC

16

A doubt about blockchain technology use in our day to day lives

hey everyone, So I was doing this course on blockchain from youtube (Mainly for a research paper) and was just wondering.....If blockchain is decentralized, has these smart contracts and so many other benefits in transactions, why isn't it fully implemented yet?? I'm kinda confused abt this and no one seems to be pointing out the cons or drawbacks of blockchain

76 Comments
2024/11/26
10:04 UTC

32

What will happen to the old computers after year 9999.

68 Comments
2024/11/25
20:01 UTC

8

Must I learn COBOL

I curious about this language is it still fisible to learn it in 2024

37 Comments
2024/11/25
18:44 UTC

47

Sudoku as one-way function example?

Hi! I am a CS student and I have a presentation to make. The topic that I chose is about password storaging.
I want to put a simple example to explain to other classmates how one-way functions work, so that they can understand why hashing is secure.

Would sudoku table be a good example? Imagine that someone gives you his completed sudoku table and asks you to verify if it's done correctly. You look around for a while, do some additions, calculations and you come up with a conclusion that it is in fact done correctly.
Then the person asks you if You can tell them which were theirs initial numbers on that sudoku?
Obviously, You can't. At the moment at least. With a help of a computer You could develop an algorithm to check all the possibilities and one of them would be right, but You can't be 100% certain about which one is it.

Does that mean that completing a sudoku table is some kind of one-way function (or at least a good, simple example to explain the topic)? I am aware of the fact that we're not even sure if one-way functions actually exist.
I'm looking for insights, feedback and general ideas!
Thanks in advance!

71 Comments
2024/11/24
12:56 UTC

69

How in the world did dijkstra come up with the shunting yards algorithm

i would have never reached to that conclusion on how a compiler would solve an equation that way. If anyone can provide any more insight on how he could have come to that conclusion i would really appreciate it

10 Comments
2024/11/24
05:22 UTC

4

I have a wierd question ?

first of all, my question might be abbsurd but i ask you guys because i dont know how it works :(

so lets say 2 computers each renedering diffrent scenes on blender(or any app). focusing on cpu, is there any work or any calculations they do same ? well we can go as down as bits or 0's and 1's. problably there are same works they do but we are talking on a diffrent scene renders, is the work the cpu's doing "same" has considerable enough workload ?

idk if my english is good enough to explain this sorry again, so ill try to give example ;

b1 and b2 computers rendering diffrent scenes on blender. they both using %100 cpu's. what precent cpu usage is doing the same calculations on both computers ? i know you cant give Any precent or anything but i just wonder is it considerable enough like %10 or %20 ??

you can ask any questions if you didnt understand, its all my fault. im kinda dumb

18 Comments
2024/11/23
18:19 UTC

29

Computer arithmetic question, why does the computer deal with negative numbers in 3 different ways?

For integers, it uses CA2,

for floating point numbers, it uses a bit sign,

and for the exponent within the floating point representation, it uses a bias.

Wouldn't it make more sense for it to use 1 universal way everywhere? (preferably not a bit sign to access a larger amount of values)

34 Comments
2024/11/23
13:23 UTC

9

Computer architecture book suggestions

I thought about building a small computer with raspberry pi Pico and a 6502 but I don't know much about computer architecture, what are good books to deepen my understandig?

4 Comments
2024/11/23
13:15 UTC

75

If every program/data can be seen as a single binary number, could you compress it by just storing that number's prime factors?

Basically title, wouldn't that be close to being the tightest possible compression that doesn't need some outlandish or specific interpretation to unpack? Probably it's hard to find the prime factors of very large numbers, which is why this isn't done, but unpacking that data without any loss in content would be very efficient (just multiply the prime factors, write the result in binary and read that binary as code/some data format)

65 Comments
2024/11/22
12:53 UTC

Back To Top