Learning path

Full curriculum

Full curriculum

Unit content

Lower bounds for comparison sorting

A comparison sort can be modeled as a decision tree whose internal nodes are comparisons and whose leaves represent possible input orderings.

For $n$ distinct elements, a correct algorithm must be able to distinguish all

$$n!$$

possible relative orders. A binary decision tree with height $h$ has at most $2^h$ leaves, so

$$2^h\ge n!.$$

Therefore

$$h\ge \log_2(n!).$$

Since

$$\log(n!)=\Theta(n\log n),$$

any general comparison sort requires

$$\Omega(n\log n)$$

comparisons in the worst case.

This is a lower bound on the model, not on sorting under every possible representation. Algorithms such as counting or radix sort can beat it by using information other than pairwise comparisons.