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
124
Upvotes
View all comments
Show parent comment
2
u/TwillAffirmer Sep 19 '26
An insertion sort has a worst case time complexity of Θ(n^2) and a best case time complexity of Θ(n).
O(n) does NOT refer to "worst case" and Θ(n) does NOT mean that best case and worst case are asymptotically the same. Θ, O, and Ω are all applied to a single, definite, fully determined function of one variable. The worst case time complexity is one function of n, and the best case time complexity is a completely different function of n, and you can pick either of those functions and use Θ, O, and Ω to describe it. You can't use a single expression O(n^2) to say that best and worst case are both bounded by k*n^2, because they are two different functions, and big O notation only applies to one function at a time.
I think it is this misconception that has led to the overuse of big O. In most cases, Θ is more specific and appropriate.