3.7.3 · D5Algorithm Paradigms
Question bank — Greedy — exchange argument proof technique
Notation used on this page (read first)
The diagram below shows this chain shrinking the disagreements down to zero.

Recall Statements of the tools referenced below (so you needn't chase links)
- Smith's rule: to minimise weighted completion time , schedule jobs in increasing order of the ratio . Plain SPT (sort by ) is the special case .
- Huffman sibling lemma: in some optimal prefix-code tree, the two lowest-frequency symbols are sibling leaves at maximum depth. Proved by two swaps (, ) whose combined cost change .
- Exchange chain: the sequence above, each link no worse than the last.
Before you start, keep three obligations of every exchange proof in mind — they recur constantly:
Recall The three things an exchange proof must always establish
(1) The swapped solution is still feasible (a legal solution). (2) is no worse than . (3) agrees with greedy in one more place, so induction terminates at . Miss any one and the proof is broken.
True or false — justify
An exchange argument proves greedy is optimal by improving greedy's own output
False — you never touch ; you take an arbitrary optimal and edit it toward , showing is no worse than .
If a single swap makes the objective strictly better, the original solution could not have been optimal
True — that is a contradiction: an optimal solution admits no strictly-improving edit, so the configuration you swapped away (an inversion) cannot exist in any optimum.
A swap that leaves the objective exactly equal is useless for the proof
False — "equal" is enough; it shows some optimum agrees with greedy one more place, which is all counting problems like activity selection need.
Exchange arguments and greedy-stays-ahead are the same technique with different names
False — stays-ahead is a measure-based induction showing greedy is never behind; exchange physically swaps elements in . Both prove optimality but by different mechanisms.
The exchange argument requires the objective to be a sum
False — it requires that a local swap changes only a bounded, computable piece of the objective; sums make this easy but any objective with that locality works.
Once you show one swap doesn't hurt, you are done
False — you must also argue the swaps terminate: each reduces the number of disagreements with , so finitely many reach (that is the exchange chain).
For weighted completion time, sorting by processing time is still optimal
False — the correct order is by ratio (Smith's rule); alone is the special case .
In the Huffman sibling lemma, showing the single swap is finishes the proof
False — the construction performs two swaps ( and ); you must show the sum of both cost-change terms is .
Every greedy algorithm can be proven correct by an exchange argument
False — some need matroid theory or a DP-based comparison; exchange is the workhorse for ordering/scheduling but not universal.
If greedy and optimal agree at every index, no swap is needed
True — that is the base case; there is no first disagreement, so and .
Spot the error
"I swapped two jobs and cost dropped, so greedy is better than optimal."
The error: optimal cannot be beaten, so this means the starting solution was not optimal — the swap proves an inversion is impossible in any optimum, not that greedy beats OPT.
"I picked any index where and differ and swapped there."
The error: you must swap at the first disagreement (smallest with ) so the already-matching prefix is preserved; an arbitrary index breaks the induction toward .
"In activity selection I replaced by and just checked the count went up."
The error: forgetting feasibility — you must first argue so later activities still fit; only then is the equal count meaningful.
"For SPT I computed only changes when I swap adjacent ."
The error: both and change; jobs before and after are untouched, but the pair's two completion times both shift, and the difference comes from both.
"The swap changed jobs far from the swapped pair too, so I recomputed the whole schedule."
The error (opposite mistake): for an adjacent swap, jobs outside the pair keep identical completion times; recomputing everything is wasted work and hides the clean result.
"Greedy is locally optimal at each step, so it must be globally optimal."
The error: local ≠ global; coin change with making gives greedy (3 coins) vs optimal (2). Only a contradiction/exchange proof certifies correctness.
"My exchange proof shows is no worse, so I'm done — I'll skip checking is legal."
The error: a "no worse" solution that violates constraints proves nothing; feasibility is a separate, mandatory obligation.
"In Huffman I assumed are the smallest-frequency leaves."
The error: are the smallest-frequency symbols; are the deepest sibling leaves. These are generally different, and the whole lemma is about relating them.
Why questions
Why must appear somewhere later in before we can swap
Because greedy never wastes a choice, the element is part of the solution set, so if is optimal it contains at some position to swap into place .
Why does putting the shorter job first reduce
The job finishing second "pays" the first job's length inside its completion time; making the first job the shorter one shrinks that doubled contribution, so the sum drops by .
Why does the exchange chain guarantee
Each link of the chain satisfies ; telescoping the inequalities gives .
Why is "earliest finish time" the right greedy criterion for activity selection
Because guarantees any activity compatible with is still compatible with , so the swap preserves feasibility — the criterion is chosen precisely to make obligation (1) automatic.
Why does the weighted inversion swap change cost by
Swapping adjacent moves earlier (saving ) and later (costing ); the net is , non-negative exactly when .
Why do we need induction and not just one swap
One swap fixes only the first disagreement; induction on the matching prefix repeats the argument until the whole solution equals .
Why is the objective decrease in Example 1 strict but in Example 2 only weak
SPT is a minimisation with distinct lengths so removing an inversion strictly lowers cost; activity selection counts picks, so a same-count replacement is only "no worse", not strictly better.
Edge cases
What if two jobs have equal processing time,
The swap gives difference ; both orders are optimal, so greedy's tie-breaking is harmless and the "no inversions" statement still holds weakly.
What if already equals from the start
Then there is no first disagreement; the induction base case applies and trivially.
What if all activities in the selection problem are mutually overlapping
Greedy picks exactly one (the earliest-finishing); the optimum is also one, and the single replacement shows they match.
What if a job has length zero,
It contributes to any doubled term and never creates a beneficial inversion; SPT places it first harmlessly and the proof is unaffected.
What if the Huffman alphabet has size one (a single symbol)
There is no sibling pair, so the swap in the lemma cannot even be set up; this is a degenerate base case — a one-symbol code is a single leaf of depth , trivially optimal, and the lemma simply doesn't apply until the alphabet has symbols.
What if the two smallest Huffman frequencies are equal,
Both terms of still evaluate to (non-negative)(non-positive); ties just mean multiple optimal trees exist, all reachable by the swap.
What if in Huffman the smallest symbols are already the deepest siblings
Then , , the depth differences are , so and no swap is needed — the base configuration already satisfies the lemma.
What if there is only one job (or one activity)
There is nothing to swap; greedy's single choice is trivially the only feasible solution, hence optimal.
What if weights are all equal in Smith's rule
The ratio reduces to (times a constant), recovering plain SPT — the unweighted case is Smith's rule specialised to .