WHY does this matter? It tells you merge sort / heapsort (O(nlogn)) are asymptotically optimal — no clever comparison-only algorithm can ever beat them. It also explains WHY counting sort / radix sort (O(n)) must cheat: they use the values themselves (indexing into buckets), not just comparisons.
We want a lower bound on the heighth of the decision tree.
Step 1 — Every permutation needs its own leaf.
There are n! distinct orderings of n distinct elements. The algorithm must output the correct one for each input. If two different required permutations shared the same leaf, the algorithm would output the same answer for both — wrong for at least one.
Why this step? The leaf is the final answer; one answer per leaf, and we need every correct answer reachable. So:
(number of leaves)≥n!
Step 2 — A binary tree of height h has at most 2h leaves.
At depth 0 there's 1 node; each level at most doubles. A tree of height h has at most 2h leaves.
Why this step? Each comparison has only 2 outcomes, so the tree is binary, and h comparisons ⇒ at most 2h distinct root-to-leaf paths.
Step 3 — Combine.2h≥(leaves)≥n!⟹h≥log2(n!)
Step 4 — Bound log2(n!) from below.
We need log2(n!)=Ω(nlogn). Use the lower half of the factorial:
n!=1⋅2⋯n≥n/2 terms, each≥n/22n⋅(2n+1)⋯n≥(2n)n/2
Why this step? Throwing away the small factors (1,2,…,2n−1) only makes the product smaller, and every remaining factor is ≥n/2 — a clean, easy bound. Taking log2:
log2(n!)≥2nlog22n=2n(log2n−1)=Ω(nlogn).
Imagine I shuffle 3 cards and you must put them in order, but you're blindfolded — you can only ask me "is this card smaller than that one?" Each question gets a yes/no. With q questions you can tell apart at most 2q different situations. But 3 cards can be shuffled 3×2×1=6 ways! Since 22=4<6, two questions aren't enough — you must ask at least 3. For n cards there are n! shuffles, so you need about nlogn questions. That's why no blindfold (comparison-only) sorter can be super fast. The clever sorters that are fast cheat by looking at the numbers instead of just asking comparisons.
Socho tum blindfolded ho aur tumhe cards ko sorted order me lagana hai, par tum sirf ek hi sawaal puch sakte ho: "kya yeh card us card se chhota hai?" — yes ya no. Har comparison ek yes/no question hai. Yahi hota hai har comparison sort (merge sort, quicksort, heapsort) ke andar — wo sirf elements compare karte hain, unki actual value ko "dekhte" nahi.
Ab maths: n elements ko n! tarah se arrange kiya ja sakta hai. Tumhe pata lagana hai input kaunsi arrangement hai — yani n! possible answers me se ek. Agar tum k yes/no questions poochte ho, toh tum sirf 2k alag-alag cases ko distinguish kar sakte ho. Sahi answer dene ke liye chahiye 2k≥n!, jisse k≥log2(n!)≈nlog2n. Isi liye worst case me koi bhi comparison sort Ω(nlogn) comparisons se kam nahi kar sakta.
Hum isko ek decision tree se prove karte hain: har internal node ek comparison, har leaf ek output permutation. Tree ko kam se kam n! leaves chahiye, aur binary tree of height h me max 2h leaves hote hain — bas isi se result nikal aata hai. Iska matlab merge sort already optimal hai, usse fast comparison-based kuch nahi ho sakta.
Aur ek important baat: counting sort / radix sort jo O(n) me chalte hain, wo is bound ko todte nahi — kyunki wo comparison sort hain hi nahi! Wo values ko directly array index ki tarah use karte hain. Toh rule yaad rakho: bound sirf "comparison-only" algorithms par lagta hai.