3.7.3 · D1Algorithm Paradigms

Foundations — Greedy — exchange argument proof technique

2,811 words13 min readBack to topic

This page is the ground floor of the exchange-argument note. Before you can read a single line of that proof, you need to own every symbol it throws at you. We build each one from a picture — no symbol appears here until you have seen what it means.


0. The scene: what problem are we even in?

Almost every exchange proof lives in a scheduling or choosing world. Picture a single machine — a printer, a CPU, one busy person — that can do only one task at a time. You have a pile of jobs. You must decide the order to do them in. Different orders cost different amounts. We want the cheapest order.

A greedy rule is a simple recipe for deciding the order without looking ahead: at each step, pick the job that scores best on one fixed criterion. Two greedy rules you will meet in the parent note:

  • Shortest-Job-First (SPT): always run the shortest not-yet-done job next.
  • Smallest-ratio-first (Smith's rule): always run the job with the smallest next (used when jobs have importance weights — see §4).

Everything below is vocabulary for talking about that picture precisely.


1. A job and its length

  • Plain words: = "how long job number takes."
  • Picture: in Figure 1 each job is a coloured bar; the width of the bar is . A wide bar = a long job.
  • Why we need it: the whole game is about ordering jobs, and the cost depends on how long each one takes. Without lengths there is nothing to optimise.

The little hanging below is a subscript — it is not multiplication. is read "p-sub-k" and just means "the belonging to job ." So is the length of job 3.


2. Completion time

  • Plain words: "what time is it when job is done?"
  • Picture: below.
  • Why we need it: the cost we minimise is built out of these finish-times. It is the number the whole topic cares about.

The key insight the picture shows: a job's completion time is the sum of the lengths of every job at or before it in the order. If the order is job A (length 3), then job B (length 2), then: Job B had to wait for A to finish first — that waiting is baked into . This is exactly why order matters.


3. The sum symbol

  • Plain words: — one term per job, no job left out.
  • Picture: stack every job's finish-time and total the heights.
  • Why we need it: our objective — the thing we minimise — is the total completion time . It rewards finishing jobs early, because an early finish is a small number added to the pile.

4. Weight and the ratio

  • Plain words: importance dial for each job.
  • Picture: in the sunset figure, imagine each bar also has a brightness — brighter = more important = higher weight.
  • Why we need it: the general objective is the weighted total : an important job finishing late costs a lot, an unimportant one finishing late costs little. When all this collapses back to plain .

The parent note's mistake-box uses the ratio ("length divided by importance"). Small ratio = short and important = do it first. This is Smith's rule (see Smith's rule — weighted completion time).


5. The number of jobs , and two solutions (greedy) and (optimal)

  • Plain words: = "how many jobs there are"; = "what greedy does"; = "a true champion answer." Both lists contain exactly the same jobs — only the order differs.
  • Picture: two rows of the same coloured bars, possibly in different left-to-right orders.
  • Why we need it: the whole proof compares these two lists position by position. The parentheses are just an ordered list is the first thing done, the last. The subscript is a position, not a job number.

6. Cost and OPT

  • Plain words: = a machine that eats any ordering and spits out its price tag; = the lowest price tag that exists.
  • Why we need it: "optimal" is defined by . The proof's punchline is , i.e. greedy hits the best price.

7. The inequality and "no worse"

The engine of every exchange proof is one inequality: .

  • Picture: a see-saw that after the swap tips down or stays level, never up.

8. The swap (exchange) itself, and an inversion

  • Picture: below — grab two bars, cross the arrows, put each where the other was.
  • Why we need it: the proof repeatedly removes inversions by swapping. Each swap fixes one disagreement between and .

Because only the swapped pair moves, only their completion times change — every other job starts and ends at the same clock time. That is what makes the cost change easy to compute (just two terms).


9. First difference, index , twin at position

  • Plain words: find the earliest spot the two lists differ; drag greedy's choice from wherever it hides in up to that spot.
  • Why the first difference: so that the part already matching greedy stays matched. This lets us make steady progress toward and guarantees the process stops (finitely many disagreements, each swap kills one). See the Induction idea below.

10. Telescoping and the final chain

  • Plain words: a domino line of orderings, each no worse than the one before, starting at an optimal and ending exactly at after steps.
  • Picture: a staircase that only ever steps down or flat.

11. Two proof flavours you'll meet

Both live under the umbrella of greedy algorithms, and both are alternatives to (usually heavier) dynamic programming proofs.


Prerequisite map

job k and length p_k

completion time C_k

sum notation total cost

weight w_k and ratio

n jobs ordering G and O

cost and OPT

inequality no worse

swap and inversion

first difference i and twin j

telescoping chain O_i and m

exchange argument proof

induction and contradiction


Equipment checklist

Cover the right side; can you answer each before reading it?

What is a greedy rule, in one line?
A recipe that picks the best-scoring choice by one fixed criterion at each step, without looking ahead (e.g. shortest-job-first).
What does the subscript in mean — is it multiplication?
No — it is "p belonging to job ", read "p-sub-k". Not multiplication.
How do you compute a job's completion time ?
Sum the lengths of every job at or before it in the running order.
What does stand for, and what is the range?
— summed over all jobs, none left out.
What is the objective when jobs have importance weights?
The weighted total ; sort by the ratio (Smith's rule).
What is ?
The total number of jobs to schedule; and each list all of them.
What are and — numbers or something else?
Whole orderings (sequences of jobs); we compare their costs, which are numbers.
What does the dot in mean?
A placeholder — put any ordering inside the brackets to get that ordering's price.
Define .
The smallest cost any ordering can possibly achieve.
Why do exchange proofs use and not ?
Because a swap may tie (equal cost) or improve; "no worse" is exactly .
What is an inversion (unweighted and weighted)?
Two adjacent jobs in wrong order for the greedy rule: longer-before-shorter (unweighted), or larger--before-smaller (weighted).
After a single swap, whose completion times change?
Only the two swapped jobs'; everyone else keeps the same start and finish time.
Why must we swap at the first difference ?
To keep the already-matching prefix matched and guarantee finite progress toward .
What are and in the telescoping chain?
is the ordering after swaps; is the finite number of swaps needed to reach ().
Why does chaining many "" steps give one inequality?
Each step is no worse than the last, so substituting them collapses (telescopes) to .

Next: return to the parent note and read the 5-step skeleton — every symbol there is now yours.