WHY yeh matter karta hai? Yeh batata hai ki merge sort / heapsort (O(nlogn)) asymptotically optimal hain — koi bhi clever comparison-only algorithm unhe kabhi beat nahi kar sakta. Yeh yeh bhi explain karta hai ki counting sort / radix sort (O(n)) ko "cheat" kyun karna padta hai: woh sirf comparisons nahi, balki values khud use karte hain (buckets mein indexing karke).
Hum decision tree ki heighth par ek lower bound chahte hain.
Step 1 — Har permutation ko apna leaf chahiye.n distinct elements ke n! distinct orderings hain. Algorithm ko har input ke liye correct one output karna hai. Agar do alag required permutations ek hi leaf share karti, toh algorithm dono ke liye same answer deta — kam se kam ek ke liye galat.
Yeh step kyun? Leaf final answer hai; ek answer per leaf, aur humhe har correct answer reachable chahiye. Toh:
(number of leaves)≥n!
Step 2 — Height h ka ek binary tree at most 2h leaves rakhta hai.
Depth 0 par 1 node hai; har level at most double hoti hai. Height h ka tree at most 2h leaves rakhta hai.
Yeh step kyun? Har comparison ke sirf 2 outcomes hain, toh tree binary hai, aur h comparisons ⇒ at most 2h distinct root-to-leaf paths.
Step 3 — Combine karo.2h≥(leaves)≥n!⟹h≥log2(n!)
Step 4 — log2(n!) ko neeche se bound karo.
Humhe log2(n!)=Ω(nlogn) chahiye. Factorial ka lower half use karo:
n!=1⋅2⋯n≥n/2 terms, each≥n/22n⋅(2n+1)⋯n≥(2n)n/2
Yeh step kyun? Chhote factors (1,2,…,2n−1) hata do — product sirf chota hota hai, aur bacha hua har factor ≥n/2 hai — ek clean, easy bound. log2 lete hain:
log2(n!)≥2nlog22n=2n(log2n−1)=Ω(nlogn).
Recall Feynman: ek 12-saal ke bachche ko explain karo
Socho maine 3 cards shuffle kiye aur tumhe unhe order mein rakhna hai, lekin tum blindfolded ho — tum sirf mujhse pooch sakte ho "kya yeh card us se chhota hai?" Har question ka yes/no milta hai. q questions se tum at most 2q alag situations bata sakte ho. Lekin 3 cards 3×2×1=6 tarike se shuffle ho sakte hain! Kyunki 22=4<6, do questions kaafi nahi — tumhe kam se kam 3 poochne padenge. n cards ke liye n! shuffles hain, toh tumhe roughly nlogn questions chahiye. Isliye koi bhi blindfold (comparison-only) sorter super fast nahi ho sakta. Jo clever sorters actually fast hain woh numbers ko directly dekhke cheat karte hain, sirf comparisons poochne ki jagah.