time-complexityquickselect

Quick-Select worst-case scenario (Θ(n^2) or O(n^2)?)


I have been trying to understand the Quick-Select algorithm and I have found two different values for the complexity of the worst-case running time.

For example, This website claims that worst-case time complexity is Θ(n^2), whilst GeeksforGeeks claims that it's O(n^2).

Can someone help me understand which one is correct and why this is the case?


Solution

  • Both are correct, but using Θ is a stronger statement. Big O notation gives an asymptotic upper bound, whereas big Theta notation gives the actual asymptotic growth rate.

    As an analogy, imagine Alice and Bob are both counting somebody's legs. Alice says legs = 2, and Bob says legs ≤ 2. Alice and Bob are both correct, but Alice's statement is stronger.

    In informal use, it's quite common to write O when you could have written the stronger statement with Θ, just because most people's keyboards don't have a Θ key.