Algorithms and Data Structures · Middle · Question 7 of 75

Why can't any comparison sort beat O(n log n) in the worst case?

Explanation

Each comparison has two outcomes, so k comparisons distinguish at most 2ᵏ orderings. To identify one of n! orderings you need log₂(n!) comparisons, which is Θ(n log n).

Further reading

Problem with a question

Algorithms and Data Structures · Middle · question 7

Test yourself

Take the Algorithms and Data Structures · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz