On this page
Bubble sort, insertion sort, merge sort and quicksort all work by asking one question again and again: is this item bigger than that one? Lecture notes from Carnegie Mellon's algorithms course prove that any such method must make Ω(n log n) comparisons in the worst case (CMU 15-451 lecture notes on sorting lower bounds). Here is why, with numbers you can check by hand.
What is the decision-tree argument for sorting?
Picture the algorithm as a tree. Each internal node is one comparison, such as 'is a < b?', with a branch for each answer. Each leaf is one finished order of the items. The diagram at the top shows the tree for three items.
Two facts finish the proof, both laid out in the CMU notes:
n distinct items can arrive in n! different orders, and each order needs a different rearrangement to fix it, so the tree needs at least n! leaves.
A binary tree of height h has at most 2^h leaves. So 2^h ≥ n!, which means h ≥ log₂(n!).
The height is the number of comparisons on the longest path: the worst case. The notes frame it as 20 questions with an adversary who always picks the answer that keeps more orders alive, so each comparison at best halves the possibilities. They also show the bound holds on average and for randomised algorithms.
How does log₂(n!) become n log₂ n − 1.44n?
Stirling's approximation in binary form says log₂ n! = n log₂ n − n log₂ e + O(log₂ n) (Stirling's approximation). Since log₂ e ≈ 1.4427, the leading terms are n log₂ n − 1.44n. The leftover error is about ½ log₂(2πn).
The −1.44n changes the constant, not the growth rate, so no comparison sort's worst case can grow more slowly than n log n. See our guide to Big-O notation and growth rates, and for where the 1.44 comes from, our explainer on Stirling's approximation for n!.
How many comparisons does it take to sort 3 or 5 items?
Apply h ≥ log₂(n!) from the CMU notes and the Stirling form:
3 items: 3! = 6 orders. log₂ 6 ≈ 2.58, so you need at least 3 comparisons. Two comparisons give only 4 outcomes, too few for 6 orders. In the tree above, four of the six leaves sit 3 comparisons deep.
5 items: 5! = 120 orders. log₂ 120 ≈ 6.91, so you need at least 7. Six comparisons give 64 outcomes; seven give 128, just enough.
1,000 items: log₂(1000!) ≈ 8,529.4, so at least 8,530. Stirling's leading terms give 8,523.1; the ½ log₂(2π × 1000) ≈ 6.3 correction closes the gap.
For small n the bound is often exactly right. The OEIS sequence for the minimum number of comparisons needed to sort n elements begins 0, 1, 3, 5, 7, 10, 13 (OEIS A036604), so 3 items really need 3 and 5 items really need 7. It is not always exact: for 12 items, ⌈log₂ 12!⌉ is 29 but the true minimum is 30 (comparison sort table).
Try it: list the 6 orders of a, b and c and cross out what each answer rules out. Two questions can pin down some orders, never all six.
How do counting sort and radix sort beat n log n?
The bound covers only algorithms that learn about items by comparing them.
Counting sort uses each key as an array index: it counts the items with each value, then uses running totals to place them, in O(n + k) time where k is the range of key values (counting sort). For the marks of 10 lakh students, each a whole number from 0 to 100, counting sort needs a couple of passes and 101 counters. Any comparison sort needs, in the worst case, about 18.5 million comparisons, from n log₂ n − 1.44n with n = 1,000,000 (Stirling's approximation).
Radix sort works digit by digit, dropping each item into a bucket for its current digit without comparing it to any other item, in O(d·n) time for keys of d digits (radix sort). The catch: these linear times assume keys of constant size (comparison sort).
How do you use the bound in an exam or interview?
Asked to sort faster than n log n? First ask what you know about the keys.
Only comparisons allowed: impossible. Count the n! orders and quote log₂(n!).
Whole numbers in a small range: counting sort.
Fixed-length keys such as roll numbers, PIN codes or dates: radix sort.
Lower bound for another problem: if each of N outputs is the only right answer for some input, take log₂ N.
For comparisons fixed in advance, read our post on sorting networks and the 0-1 principle.
If the step from n! leaves to log₂(n!) still feels slippery, the Fermi Concept Library covers every concept in mathematics and computing. Then draw the tree for 4 items, which needs 5 comparisons, and work through related problems in the Fermi Problem Library, whose step-by-step solver explains the reasoning.



