Chapter 10 · Iterative Improvement
The Stable Marriage Problem
Gale–Shapley: free people propose down their preference lists; the other side keeps the best offer so far. After at most n² proposals the matching has no blocking pair — and it is optimal for whoever proposes.
current proposal
currently matched
rejected / dumped
free
Ranking matrix (row man's rank of her, column woman's rank of him)
proposal now
matched pair
struck = rejected or dumped
Blocking-pair checker
Build any matching: click a cell to pair that man with that woman (clicking again un-pairs). When everyone has a partner, the checker lists every blocking pair — a man and a woman who both prefer each other to their partners.
Show all n! matchings and which are stable (brute force)
How to read this
- Each matrix cell “a, b”: a = where the row's man ranks the column's woman, b = where she ranks him (1 = favorite). Levitin's Figure 10.11 uses the same format.
- Yellow arrow = a proposal. Green lines/boxes = current pairs. A red ✕ = rejection; a red dashed line = a partner being dumped for someone better.
- Free proposers are listed under the picture. We always pick the first free one in list order, so a rejected proposer proposes again right away.
- A proposer only moves down the list; a receiver only trades up. That's why it ends in at most n² proposals and why no blocking pair survives.
Try this
- Levitin §10.4 example: predict each response. Tom's proposal to Lea is the twist — Lea trades Bob (her #2) for Tom (her #1), and Bob falls to Ann.
- In the checker, pair (Bob, Ann), (Jim, Lea), (Tom, Sue). The checker finds the blocking pair (Bob, Lea): he ranks her 1 > 2, she ranks him 2 > 3.
- Load Two different stable matchings and run with men proposing, then women proposing. Each man gets his #1 in the first run and his #3 in the second — same instance, both stable.
- Open "all n! matchings" for the Levitin §10.4 example: exactly one of the 6 is stable, so both proposing orders must find it.
- Pick n = 5 and Random a few times. Count proposals: never more than n² = 25 (in fact at most n² − n + 1 = 21).
Go deeper
📖 Lesson 10: Iterative Improvement
🏟️ Arena · Chapter 10
🧩 Problem: gale-shapley
🧩 Problem: is-stable-matching
🎮 Bipartite matching
🎮 Max-flow
Reference: Levitin §10.4. Real uses: residency matching of medical graduates to hospitals, school choice, and the market-design work honored by the 2012 Nobel Prize in Economic Sciences.