/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

424,458 Subscribers

3

How is searching through a hashmap O(1) time complexity?

I'm learning how to use hashmaps. From what I can tell, they're just a disorganized version of an array. What I don't understand is how it's physically possible to search through it in O(1) time complexity. I would expect something like this to be at least O(log n) time, which is what it would be if you binary-searched a sorted array with the hashes. How is it possible to find out if an item exists, let alone how many times it occurs, in any sort of list in consistent time regardless of the list's size?

7 Comments
2024/12/31
17:54 UTC

0

Which is your favorite software design pattern and why?

I will go first, mine is the observer pattern, it is very intuitive and relatable the use cases are obvious.

Use case- If a state of a particular object should get updated, other states that are dependent on it should be updated too.

3 Comments
2024/12/31
17:45 UTC

4

How do I simulate brownian motion?

I am adding wind to my simulation and I dont want to compute brownian motion for each particle so how can I simulate it accuratelishly.

12 Comments
2024/12/29
22:53 UTC

0

PSA: Kleene's name is pronounced Kleen-EE not Kleen-AY (as Wikipedia puts it, quite wrongly, I got proof)

Source --- Scott (who, besides LCF, invented denotational semantics) knew Kleene IRL so he probably knows how to pronounce his name. This is the most egregious mathematician/computer scientist name mispronunciation. Just trailing behind calling Gödel "Gerr-del" and the third one being calling Kernighan "KerniGAN" (it's KerniHAN --- he's not a real mathematician or computer scientist anyways, more of a compsci communicator). If you got more stuff like these, please do tell, I'm looking towards being a more fun guy at the parties I throw with my dollies.

10 Comments
2024/12/29
16:14 UTC

6

Keeping up

I wanted to know is there an app or a site that could helps stay apace with technology. I use to work in the industry but no longer. That being said I’d like to revitalize that passion and am looking for something akin to Duolingo if it even exist that will have me engaged so I can learn better. Or if that doesn’t exist literature Is fine as well, I’d appreciate any recommendations at the end of the day. Something that talks about hardware components like ram as well as software. And I apologize if this is worded oddly. For some reason the mobile app told me I was violating the sub before finishing two sentences and I had to rephrase everything.

2 Comments
2024/12/28
20:30 UTC

9

Ever heard of Binary Scaling?

Hi,

I have 16 bits that contain data encoded in Binary Scaling.

The format is "B-4.19"

What are the steps to convert this to a floating point variable?

Happy New Year,

V/r

7 Comments
2024/12/28
03:30 UTC

10

Prove …. Is O(N)…

No matter how hard I tried I can’t get my head around proving a function is Big O of anything. For instance I don’t get where they’re getting G of X from I just get anything at all. Can someone please explain to me and dumb it down as much as possible

An example question would be prove 5n + 3 is O(N) it would be appreciated if you could explain step by step using examples

16 Comments
2024/12/26
22:45 UTC

27

Would there still be a theoretical concept of computing without Alan Turing?

9 Comments
2024/12/26
22:14 UTC

0

Compile Time Errors : C++

I read through many articles and watched many youtube videos about C++ problems, many of them complained about this language by had comparision with Rust. People complained more about memory safety, error messages and run time errors.

As my understanding i also faced errors at runtime not in compile time while learning c++ and also those criticism(memory safety, error messages and run time errors) about c++ is compilers or the language itself don't throw proper errors/error messages at compile time.

My Questions are,

Is the compile time errors are the answer for all the mentioned criticism about c++?.

Can C++ developers make compilers throws errors at compile time? or is it really has any problems in the compilers or ISO standards?. I don't really understand this.

I am eager to wait to read all of your opinions about this.

2 Comments
2024/12/25
14:07 UTC

43

Is there a mistake in this MIT Video?

Here:

https://preview.redd.it/xk84h2lrrr8e1.png?width=1653&format=png&auto=webp&s=897e6741643f47c8b0cf9ab38e055802873254cd

They claim the only base case of Merge Sort is for an empty array, but I'm pretty sure if i = 1 and j = 2, then m = 1 and we have i=1, m=1 which will be empty array so ok but m=1, j=2 will be array of size 1 again, and it's infinite?

10 Comments
2024/12/24
09:59 UTC

1

Positive weight cycles in Graph?

I am trying to wrap my head around cycles in graph. The book CLRS states that a graph cannot even contain positive weight cycles. (Negative weight cycles were already ruled out).

Pg 646 under heading Cycles:

Can a shortest path contain a cycle? As we have just seen, it cannot contain a weight cycle. Nor can it contain a positive-weight cycle, since removing the cycle from the path produces a path with the same source and destination and a lower path weigh.

But then the book purposely include examples that contain cycles! In the case of Bellman-Ford, the book clearly indicates that the graph contains a cycle. So that's fine. But for Dijkstra, I can clearly see a cycle forming in Figure 24.6 on page 659. The cycles forms among s -> y -> z -> s vertices. It's forming a +ve weight cycle. Yet it does, seemingly, calculate correct shortest-distance between vertices.

Did I miss something?

Can a positive weight cycle exist in a graph when computing correct shortest-distance from vertex 'u' to 'v'?

2 Comments
2024/12/23
22:54 UTC

40

What's on Your Bookshelves? Recommendations for Programming and Architecture Books

Here in Illinois, my wife and I enjoy participating in the 2024 Library Crawl, traveling across the state to explore different libraries and discover new books. However, I often struggle to find up-to-date Computer Science or Programming books that are relevant to my work.

I’d love to compile a list of the best books on programming and computer architecture to recommend to my local public library. Do you have any suggestions?

19 Comments
2024/12/23
21:50 UTC

13

Unpacking a remark on hash table efficiency

In Lecture 5 of MIT's 6.006 Introduction to Algorithms, Professor Ku answers a question as to why the build operation of a hash table (using chaining) is worst case expected linear. Paraphrased as follows:

"Why [do we refer to hash table build operation complexity as] 'expected'? When we build the table, each insert operation requires looking up the key, and if the hashed index is already in use, looking down the chain of elements stored at that index. If I happen to know that all my keys are unique in my input, then I do not need to perform the check and I can get worse case linear [expected] [build] time."

I'm not sure I understand what the 'unexpected' worst case would be. I imagine it is when a check is performed for each insert (e.g., all items stored at the same hashed index). I suppose then the worst case 'unexpected' for n items would be n multiplied by the complexity factor of the 'find' method for the data structure at each index? For example, if the chain structure is a linked list (with find complexity of Theta(n)), the worst case 'unexpected' build time would be Omega(n^2)?

Similarly, I guess that the worst case 'unexpected' find time for a hash table with chaining is simply the worst case find time for the data structure used for chaining?

See the image below for how the course is presenting complexity:

https://preview.redd.it/wrbnfywxih8e1.png?width=2124&format=png&auto=webp&s=cf15eb76858e4a7c41a5213ef67f08ddd92a7af4

In particular, this question is about the use of (e) (meaning 'expected') for the build operation complexity of a hash table. The course has a lot of special notation and conceptual models, so LMK if anything needs clarification to be answered meaningfully.

4 Comments
2024/12/22
23:27 UTC

0

How to spend less time fixing bugs

I am implementing a complex algorithm. I spend most of the time, or a least a good part of it, fixing bugs. The bugs that take a lot of time are not the kind of bugs where there is some error from the interpreter - those kind of bugs can be quickly fixed because you understand the cause quickly. But the most time consuming bugs to fix are where there is a lot of executed operations, and the program simply give the wrong result at the end. And then you have to narrow it down with setting breakpoints etc. to get to the cause.

How to spend less time fixing those bugs? I don't necessarily mean how to fix them faster but also how to make less bugs like that.

Does anyone have some fancy tips?

25 Comments
2024/12/22
20:49 UTC

44

Is there a name for this algorithm?

Sorry if this doesn't follow rules, I'll remove it if needed. I want to implement an algorithm but i have no idea if it has a name i can call it by (It probably does though, since it is very simple). I want to generate a list of all combinations of n numbers from 1 to x in a particular order. I start with n number variables each assigned their respective default value from 1 to n. Then the algorithm follows 2 rules. starting from the smallest variable, if a variable can increase by 1 without being equal to the next smallest variable or being greater than x, then it does so and all variables smaller than the one being increased is reset to default values, and the algorithm loops. Otherwise, the next smallest variable is asked the same question. if no variable can be increased, then the algorithm ends. What is this called?

13 Comments
2024/12/20
01:11 UTC

13

Algorithms & Theoretical CS REUs/Summer Research Programs

Hi! I was wondering if theres any Theoretical Computer Science REU/Summer Research Programs that I could apply to? I've found very few and one of the deadlines already passed :( (I've applied to EPFL, missed ETH Zurich, have CAAR , OSU, ISTA, and DIMACS on my list)

3 Comments
2024/12/19
21:35 UTC

58

Rewatched War Games

I watched it as a kid in the early 2000’s and rewatched it last night. I know a little bit about computer science but by no means a ton, especially what it was like in the 80’s.

I know movies are not the place to look for sound reason, but the most unbelievable part to me was: this kid who is obviously very knowledgeable of computers and tech in general doesn’t know about back doors?

Is this just movies being movies or we’re back doors not common in the 80’s? Maybe only for people writing programs and such?

33 Comments
2024/12/19
18:26 UTC

1

Translate this equation from Prim's Minimum Spanning Tree

https://preview.redd.it/exntm0k55p7e1.png?width=1123&format=png&auto=webp&s=9e37de60a3c56fe6223f1e1c039637e35f4e9d79

where

A = light edges forming the minimum-spanning tree

v is vertice

v.pi is vertice's parent

V is all the vertex.

r (I don't know what this is)

This is from the CLRS book page 634. Why do I want to know this equation? Because I am trying to print the minimum spanning but I can't get the minimum distance. I can visually see that it's not minimum distance.

Any help is appreciated.

This is not a homework. I am a grown man with 7-8 years of professional experience as a Software Engineer. I am just curious.

edit: problem solved. I did indeed misunderstood the what MSTs are. I basically misunderstood the purpose of MSTs. But now I have it right and I luckily stumbled upon it when looking something else:

The Minimum Spanning Tree algorithm is used in weighed networks to find the shortest, most efficient way to connect all
the nodes in a graph: it finds the minimum set of edges that connects all the nodes, without creating any loops or cycles.

4 Comments
2024/12/19
00:09 UTC

25

Book recs to learn how computers work for senior citizen

Looking to get my grandfather a book that explains VERY basic computer / software concepts.

The text of the book should be large-ish. Does anyone have any recommendations? He wont be coding or anything like that, this is just for a curiosity read

8 Comments
2024/12/18
16:35 UTC

10

Is there some type of corollary to signed code to ensure certain code is executed?

Hi,

I've been interested in distributed computing.

I was looking at signed code which can ensure the identity of the software's author, publish and the code hasn't been altered.

My understanding is signed code ensures that the code you are getting is correct.

Can you ensure that the code you ran is correct?

Is there some way to ensure through maybe some type cryptology to ensure that the output of code is from the code mentioned?

Thanks!

6 Comments
2024/12/17
19:16 UTC

126

How Do You Stay Updated with the Tech World?

Hi everyone!

I’m a CS graduate from Germany, and I’m curious about how you all stay on top of the ever-changing tech landscape. What resources, news sites, or methods do you use to keep up with current trends, breakthroughs, and innovations in the tech/IT/computer science industry?

Do you have favorite websites, newsletters, YouTube channels, podcasts, or even communities that you recommend? I’d love to hear how you stay informed and inspired!

Thanks in advance for sharing your tips!

26 Comments
2024/12/17
13:10 UTC

5

How can I measure virtual memory performance?

I'm trying to optimize the following kernel variables, to favor latency without compromising throughput too much, on a system with an M.2:

- vm.dirty_writeback_centisecs

- vm.dirty_expire_centisecs

- vm.dirty_background_ratio

- vm.dirty_ratio

- vm.vfs_cache_pressure

- ext4 commit frequency

The problem is that each time I run various performance measurement tools I get extremely different results, the variability is huge.

I tried to somehow reduce extreme measurements by using the statistic function "trimean", which does exactly that. But even then every measurement is relatively different.

3 Comments
2024/12/17
05:39 UTC

0

Cost-benefit of scaling LLM test-time compute via reward model

A recent breakthrough by Hugging Face whereby scaling test-time compute via Llama 3b and an 8b supervisory reward model with 256 iterations outperforms Llama 70b in one try on maths.

Chagpt estimates however that this approach takes 2x the compute as 70b one try.

If that's so what's the advantage?

I see people wanting to apply the same approach to the 70b model for well above SOTA breakthroughs, but that would make it 256 times more computationally expensive, and I'm doubtful the gains would be 256x improvements from current SOTA. Would you feel able to estimate a ceiling in performance gains for the 70b model in this approach?

6 Comments
2024/12/17
04:42 UTC

1

Tiny TOC doubt.

https://preview.redd.it/3cxwhvv4097e1.png?width=637&format=png&auto=webp&s=7eabcfea91def4fe89886217b9c7cd6426847c7b

I don't know if this is the right sub to ask this, but if someone has knowledge of Theory of Computation and Finite Automata could they kindly clarify what do + and - notations here represent? An intuitive guess is that they are initial and final states but I still want to be sure about it.

7 Comments
2024/12/16
17:48 UTC

40

I might fail a class, but I think I learned the lesson

A little background. I had a fine career in journalism a few years ago. I was an editor and had a good network. However, the business got tougher and tougher with fewer and fewer jobs and less pay. Just a fact of the industry. Last year I chose to go back to school. There are, in my country, many smaller computer science degrees that teach you the basics. While they have historically been great, I felt the field had become more comptetive and I had to take a more fundamental software engineering course. Another reason is I suffer from a debilitating chronic illness and can't see mysef in the stressfull envirenment journalism is and if I need to compete with able body people, I need to get my shit together.

I am now 36 and have learned a lot, but also gotten a lot of bad habits. One really stood in the way of my success in CS.

I had learned to "jump in puddles". Long time in radio made me quick to learn something on a shallow level, conduct and interview, write a script and then SOUND like I knew what I was talking about.

This made me feel I could learn quickly, but I didn't. I learned to sound like I knew what I was talking about.

I have just studied for statstics, spend countless hours on it and I am honestly not sure if I have passed. But looking back I realized that instead of jumping into an ocean I tried to learn by jumping in puddles. Getting a shallow knowledge of everything and then move on. However, in this field you need firm knowledge of certain areas before puddle jumping. I realize that if I had really focused on the subjects and gone in depth with them and then moved on I would have done so much better. In statistics a lot follow the exact same pattern and if I had just gotten really good at step one before moving on to step two, this would have been such a different experience.

At this point I feel that I finally learned the lesson and I hope this reasonates with others struggling. Sometimes it is not about learning, but delearning.

10 Comments
2024/12/16
15:37 UTC

268

What's new/upcoming in CS research that is going unnoticed because artificial intelligence is all we hear about atm?

70 Comments
2024/12/16
02:10 UTC

3

Questions about NLP tasks for a new low-resource language

Hi everyone

I am looking for topics for my computer science research. As for my interest in linguistics, I am thinking about applying NLP to a new language. However, All I have done so far is to fine-tune pretrained model for specific tasks. I'm not experienced much with making a tokenizer or a language model for a new language from scratch.

One of my questions so far is how do tokenizers, lemmatizers and translators deal with highly inflectional, morphologically rich languages like German, Greek, Latin, etc.

Can anyone give me an insight or any resources on such tasks on a new language?

2 Comments
2024/12/16
01:08 UTC

Back To Top