3.6.9 · D3Sorting & Searching

Worked examples — Lower bound for comparison sorts — Ω(n log n) proof via decision trees

3,079 words14 min readBack to topic

This page is the "hit every case" companion to the parent proof. There we built the whole argument once: orderings must each land on a distinct leaf, a binary tree of height has at most leaves, so and , which grows like . Here we stress-test that machinery on every kind of input it can meet — tiny , degenerate , huge , non-comparison sorts that dodge it, and exam twists.


The scenario matrix

Every worked example below is tagged with the matrix cell it covers. The goal: no cell left unvisited.

Cell Case class What breaks / is special Example
A Smallest non-trivial () tree height is an exact small integer Ex 1
B Degenerate () , height — no comparison needed Ex 2
C Medium where beats the crude exact vs. loose bound Ex 3
D Large (asymptotic) Stirling's tight constant Ex 4
E Upper meets lower (optimality) merge/heapsort are provably best Ex 5
F Bound does not apply (non-comparison sort) premise broken → escape Ex 6
G Word problem (real world) blindfold card game / tournament Ex 7
H Exam twist — partial info / duplicates fewer than outcomes → smaller bound Ex 8

Example 1 — Cell A: the smallest trees that can sort 2 and 3 items

Figure — Lower bound for comparison sorts — Ω(n log n) proof via decision trees

Example 2 — Cell B: the degenerate cases and


Example 3 — Cell C: exact bound vs. the crude bound at


Example 4 — Cell D: large and Stirling's tight constant


Example 5 — Cell E: upper bound meets lower bound (optimality)


Example 6 — Cell F: escaping the bound (non-comparison sort)


Example 7 — Cell G: the blindfold card word problem


Example 8 — Cell H: exam twist — duplicates shrink the bound


Recall The one habit that fixes every case

Always ask first: "How many distinct correct outputs are possible?" Call it . Then the worst-case comparison floor is .

  • All distinct keys → → grows like .
  • Duplicates → → smaller floor.
  • → floor .
  • Not comparison-only → the model doesn't apply, no floor at all.
Recall Self-test

Why does a repeated key lower the bound but counting sort remove it entirely? ::: Repeats cut (fewer leaves needed) but you're still comparison-only, so a floor remains; counting sort abandons comparisons altogether, so no decision-tree floor applies. Minimum worst-case comparisons to sort 5 distinct items? ::: .

Related tools used above: Big-O and Asymptotic Notation, Information Theory & Entropy, Binary Search, Quicksort.