r/computerscience • u/Significant_Virus142 • Sep 17 '26
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
118
Upvotes
View all comments
Show parent comment
4
u/not-just-yeti Sep 17 '26 edited Sep 17 '26
I agree with your gist, but be careful about phrasing: What is your function exactly? "The number of items needed to look at, to see if the collection of n items includes a particular target item?" That's not actually a function: when I input n=17 (say), there are many possible outputs (17 of them). That's why we usually make the function not "run-time on input of size n", but the "worst-case run-time over all inputs of size n" (or the average-case, or whatever). Once you clarify your function, it does have a big-Theta. (E.g., restricted to worst-case-behavior it's exactly linear, so it's bounded both above and below by n.)
But I agree with you that people usually leave this off, either assuming worst-case (or probably not really realizing they haven't defined their function for us). And in that way, you can still make sense of big-Oh and big-Omega ("I don't care which input of size 17 you use, the result is bounded above by 17" — essentially worst- or best-case without saying the words), but big-Theta wouldn't be sensible.