r/computerscience • • Sep 17 '26 • Heartwarming 1

Help Why use Big O notation?

If someone asks for big O time complexity of an algorithm but expects only the minimum of the possible big Os then is that even Big O notation anymore? cuz if the big o time complexity of an o(n) algorithm is asked then according to the condition of big O notation O(n square) would also be a valid answer

120 Upvotes

64 comments sorted by

View all comments

Show parent comment

1

u/Interesting_Debate57 Sep 20 '26

It's about the best known upper bound and the best known lower bound. Those are sometimes identical, I'm which case neither can ever be improved. But for most things that aren't sorting or reducible to sorting, there's a gap, so we know it takes at least as long as the lower bound and at worst as long as the upper bound, but we may not know either the best algorithm or the tightest bound for that algorithm, so we state what we do know instead.

Also keep in mind that there are conditions attached to these bounds. The well known bound for sorting is for a series of binary comparisons of data that doesn't have many or any duplicates in the data. Lots of data (like a list of a billion 4-digit years of birth) isn't unique and there are specialized algorithms because it's a more narrowly specified problem than the general case.