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
120
Upvotes
View all comments
Show parent comment
1
u/UniqueSignificance77 Sep 19 '26 edited Sep 19 '26
This is an interpretation problem.
The common interpretation is the number of operations the program does. Let's call the function mapping (input -> number of operations) f. For inputs where the list has length n, f has two free variables. The list L with len(L) = n and the search number s.
Regardless of what values are assigned to these two free variables, the number of operations performed by linear search is Ω(1) and O(n) where the bounds are correct over all lists L of length n and all search numbers s.
A Θ(g(n)) bound will not exist here because the tightest upper and lower bounds are not within a constant factor of each other such that it's correct for all such "cases".
Talking about the upper bound over this family using big O implicitly encodes "worst case" since this bound must hold true for all such free variables. Similarly Ω and best case.
Sure, you CAN talk about just the worst-case time complexity being Θ(n) and the best-case time complexity being Θ(1), but that's specifically ONLY talking about the maximum and minimum over these assignments and I do expect people to be specific if they're talking about only these.
When people normally talk about time complexity without explicitly mentioning specific cases, they care about bounds which hold on the whole set.