The Decision-Tree Lower Bound Proof
Overview
Any comparison-based sorting algorithm must perform comparisons in the worst case. This is a fundamental lower bound, proved by modelling the algorithm as a decision tree. Non-comparison sorts (counting, radix, bucket) evade this bound because they examine key values directly, not just pairwise orderings.
The Decision Tree Model
A comparison-based sorting algorithm can be modelled as a binary tree:
- Each internal node represents a comparison between two elements:
- The two outgoing edges represent the outcomes: Yes (true) and No (false).
- Each leaf represents a specific output permutation of the input — the sorted order.
- A path from root to leaf represents the sequence of comparisons performed for a particular input that yields that sorted permutation.
For inputs with distinct elements, there are possible permutations of the output. Each permutation must be reachable via some path in the decision tree, so the tree must have at least leaves.
The Proof
Consider an arbitrary comparison-based sorting algorithm. Let be the height of its decision tree (the maximum number of comparisons performed on any input of size ).
A binary tree of height has at most leaves (each level at most doubles the number of nodes, and leaves can only appear at the bottom). Since the tree must accommodate all possible output orderings:
Taking logs base 2:
By Stirling’s approximation, . More precisely:
Therefore . Any comparison sort performs comparisons in the worst case.
The Flaw (Non-Comparison Sorts)
The proof contains a crucial assumption: that the only way to gain information about the input is through pairwise comparisons. This is the comparison model.
Counting sort does not compare elements against each other. Instead, it uses the numeric value of a key as an array index — an operation that is not a comparison. Radix sort similarly uses digit values to route elements into buckets. These operations are not representable as decision-tree nodes of the form , so the lower bound does not constrain them.
In essence: the lower bound says “if all you can do is compare pairs of elements, you need comparisons”. Non-comparison sorts sidestep this by exploiting structural properties of the keys (bounded integer range, representable as digits, uniform distribution).
Bubble Sort: A Cautionary Tale
Bubble sort repeatedly scans the array, swapping adjacent elements that are out of order, until a full pass produces no swaps. In the worst case (reverse-sorted input), it performs passes with comparisons each, yielding total comparisons.
Bubble sort is a comparison sort and is quadratically slower than the lower bound permits. It is presented in the course as an example of what not to reinvent. Its saving grace is a nice loop invariant: after the -th pass, the largest elements are in their final sorted positions.
Significance
The decision-tree lower bound establishes a theoretical limit. It tells us that mergesort and heapsort are asymptotically optimal comparison sorts (both achieve ). It also tells us that to beat , we must abandon the comparison model — which counting, radix, and bucket sort all do.
Summary
| Property | Value |
|---|---|
| Lower bound for comparison sorts | |
| Proof technique | Decision tree with leaves |
| Key inequality | |
| Why non-comparison sorts beat it | They examine key values, not just pairwise order |
| Optimal comparison sorts | Mergesort, Heapsort (both ) |