3.6.9 · D1Sorting & Searching

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

2,030 words9 min readBack to topic

Before you can follow the proof, you must be fluent in a small pile of symbols and pictures. This page builds every one of them from zero, in the order the proof uses them. Never skip ahead — each block earns the next.


1. What "" and "elements" mean

The picture: imagine physical cards face-down on a table. We can't see the numbers directly — we can only ask "is this card's value less than that card's value?" That blindfold is the whole game.

Why the topic needs it: every bound we prove is a function of — we want to know how the effort grows as the pile gets bigger.


2. Ordering, and the "less than" symbol

The picture: two cards held up side by side. You point and ask, and I nod (yes) or shake my head (no). That is the only move you're allowed.

Why the topic needs it: a comparison sort is defined as an algorithm whose only data-dependent action is asking such questions. This restriction is the source of the whole lower bound — see Merge Sort, Heapsort, Quicksort, which all obey it.

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

3. Permutations, and the factorial ""

This is the heart of the counting. Take it slowly.

How do we count them without listing? Fill the line left to right:

  • The first slot can be any of the items → choices.
  • The second slot: one item is used up, so choices remain.
  • The third: choices … and so on down to the last slot with choice.

Multiply the choices together (because each independent choice multiplies the count):

The picture below shows the branching that produces these counts — a fan of choices that multiplies at every step.

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

Why the topic needs it: the correct sorted order is one particular permutation, but the algorithm doesn't know which one until it asks questions. So the number of possible answers it must be able to produce is exactly . That's the "many answers" side of the whole argument.


4. Powers of two, and "" as counting outcomes

First we name the quantity everything hangs on.

The picture: start with all cases in one bag. Ask a question → it splits into 2 bags. Ask again inside each → 4 bags. After questions, at most bags.

Why the topic needs it: comparisons can distinguish at most different outcomes. If we must distinguish outcomes, we need . This is the "few questions per node" side. See also Binary Search, where the same halving logic gives .


5. Logarithm "" — undoing the doubling

The inequality has trapped up in the exponent. To free , we need the tool that undoes " to the power of".

The picture: a staircase where every step doubles the height. tells you which step number sits at height .

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

Why the topic needs it: substituting converts into — turning "at least this many outcomes" into "at least this many questions". For the deeper theory of "information per bit", see Information Theory & Entropy.


6. Estimating — where "" is born

We now have , but is still a mouthful. We want a clean, familiar shape.

Take (turning the power into a product), and use the subtraction rule from Section 5:

That last expression grows like — the promised shape. For the exact constant, Stirling's Approximation gives .


7. Big-O and — the "grows like" language

Why the topic needs it: we don't care about the exact number — we care about its shape as grows. is the tool that says "at least this shape". Full treatment in Big-O and Asymptotic Notation.


How the pieces feed the topic

n items to sort

comparison a_i less than a_j is one yes-no bit

permutations n factorial possible orderings

k questions split into at most 2 to the k outcomes

need to tell apart n factorial answers

combine 2 to the k at least n factorial

logarithm frees k so k at least log2 n factorial

half factor trick bounds log2 n factorial

Big-Omega n log n lower bound

Every foundation on this page flows into the single conclusion : the floor.


Equipment checklist

Cover the right side and answer aloud. If any stalls, re-read that section before the proof.

What does count in a sorting problem?
The number of items being sorted.
What is the only operation a comparison sort may use?
A yes/no comparison like ""; it never reads the actual values.
What does the symbol count?
The number of yes/no comparisons the algorithm asks along its longest run.
What is a permutation, and how many are there of items?
One specific ordering of the items; there are of them.
Compute and explain the multiplication.
: 3 choices for the first slot, 2 for the second, 1 for the last.
Why do yes/no questions distinguish at most cases?
Each question doubles the number of tellable-apart cases (splits every case into YES and NO).
What question does answer?
"How many times must I double to reach ?" — it undoes .
Turn into a statement about , and what is in our proof?
(apply the increasing function to both sides); here .
Why is a sum, not a product?
Because , so .
Which log rule turns into ?
The subtraction rule , with .
State the half-the-factors lower bound for , and how odd is handled.
; for odd keep the top factors, each , giving at least copies.
What does assert, and how does it differ from ?
A floor: growth is at least . is a ceiling (at most); is at least.