r/learnprogramming • • Apr 05 '22

Name one programming/comp sci concept you never understood and if you understand it, try to explain it to them

Name a programming concept such as virtual functions, pointers, certain algorithms, etc that you always had a hard time understanding and why.

Someone else who reads yours and does understand it, try to explain it to them to help them learn

1.6k Upvotes

738 comments sorted by

View all comments

1

u/CodedCoder Apr 05 '22

Big O, like I understand what it does, but for the life of me have such a hard time figuring out how to use it. Every book I tried, just seems so technical and dry.

2

u/Sasquatch_actual Apr 06 '22

I can't stand using books for stuff like this.

The most simple way to learn time complexity stuff is to code up some simple demonstrations.

The trick to this is using ridiculously large datasets.

If your dataset has 10 numbers in it, anything you do is going to complete nearly instantly after you click run.

Make an array with 500 million integers in it.

Try some constant time operations. They happen instantly.

Try some linear time operations. Search for 50k random integers between 0 and 500 million. That's going to take a while (minutes) to complete. Print out a timestamp before and after that process, see how long it takes.

Do the same thing again. But this time use binary search in logarithmic time. It'll blow your mind how fast it is. A few seconds maybe.

Play with each time complexity with large enough numbers to make a difference. Some may never finish,

Look at your data structures, and their different complexity for different operations. Think how loading half a billion items would be fast or slow.

Any operations that's making you iterate over that entire length of half a billion you'll feel it, when you try it.

1

u/CodedCoder Apr 06 '22

My issue is knowing how to do it, like no one has ever explained it to me of how to get the time that’s the part that gets me like the last book I read was basically like “so one loop is 0(n) “ not saying that’s true but using it as an example and I go but how is it that, how did you get to that conclusion lol

→ More replies (3)