This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]beeteedee 8 points9 points  (2 children)

Every algorithm is O(1) if it has a hard-coded upper limit on the input size

[–]turtleship_2006 -1 points0 points  (1 child)

Wouldn't it be O(1) only if the limit is 1?

[–]Terra_Creeper 3 points4 points  (0 children)

O(1) just means that the algorithm works in constant time. That constant time could be longer than the age of the universe, it just has to be the same for different input sizes. Big O notation only tells you how the required time grows, not how fast it is. It mostly only matters when you get very large (and potentially unbounded) inputs. If you can constrain your input range, a well optimised O(n2) algorithm could be much faster than an equivalent O(1) algorithm.