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

2

u/Sjoerdiestriker Sep 18 '26

Any question in mathematics that asks "find an upper bound" implies "find a tight upper bound

I don't think this holds true. For instance, there are plenty of things you could prove from realising n! Is bounded above by nn, even if this is (both in absolute and relative terms) nowhere near a tight bound.

1

u/projexion_reflexion Sep 21 '26

Of course if big O has the n as an exponent or factorial, your algorithm is useless. 

1

u/Sjoerdiestriker Sep 22 '26

That isn't true necessarily either. Big O for algorithms just tells you how the problem scales with size, not how expensive it is for any finite size. It's perfectly possible for an algorithm to scale exponentially or superexponentially, yet still be cheap enough to be easily computable for any practical size of problem you might want to throw it at.

Likewise, it's perfectly possible to have an O(n) or O(1) algorithm that's way too expensive for any practical size of problem to ever actually execute. It'd just mean it wouldn't get much more expensive than that very quickly.

Lastly, big O is going to depend heavily on what you are actually using as a measure of size. An algorithm that scales linearly with the size of an input number scales exponentially with the number of digits of that input number, for instance.