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

Show parent comments

94

u/Rote515 Apr 05 '22

Although this comment is true, i don’t think it gets to the heart of BigO, the most important part of bigO is that it’s a time complexity estimation more than an exact time complexity which your examples do not show. For example a 3N + 2N + 2N2 algorithm has a bigO of N2 as we drop the constants and only use the fastest growing term, because as N gets large it ends up being the only term we care about from a complexity point of view.

24

u/XilamBalam Apr 05 '22

Yes, it's looking how the function "behaves at infinity" (asymptotic behaviour).

1

u/ExtraFig6 Apr 07 '22

this part gets missed a lot imo

the behavior at infinity is irrelevant if you know you only ever need n<=10.

1

u/RadioactiveHappiness Apr 24 '22

This reminds me a lot of looking at L'Hopital's Rule for evaluating limits of indeterminate functions! Excuse me, just a lowly Calc 3 student working towards taking Comp Sci this fall :)

5

u/MaxwellCE Apr 06 '22

What if the algorithm is N² + N³? Could we say that has a big O of N³, or is the N² component non-negligible?

10

u/Rote515 Apr 06 '22

BigO only ever cares about the fastest growing term, so n2 + n3 would be N3 significance doesn’t matter, consider n = 20 in the above algorithm, n2 = 400 n3 = 8000 at that point n is negligible already, now imagine n=100 or n=1000 a larger power always makes the smaller power insignificant at any non trivial n

2

u/[deleted] Apr 06 '22

Infinite limits have entered the chat

1

u/tzaeru Apr 06 '22

That's a good point yes. Honestly it's been so long I last thought about the Big O notation that I had completely forgotten about removing the constants and finding the highest term.