Study materials · photonresources.comClasses with our teachers · Photon AcademyFor IB Diploma students worldwide

Maths IA · Modelling · topic 97 of 97

Matching students to places: the Gale-Shapley algorithm · IB Maths IA idea: guide, sample graph and step-by-step plan

no blocking pair = stable

Every student ranks the schools and every school ranks the students. Can you pair them so that no student and school would both rather swap? Gale and Shapley proved you always can, and gave a method that finds it.

Difficulty●●● Stretch
KitPython or a spreadsheet for simulation, paper for the proofs, your GDC
TimeAbout 15 hours
FitsAA SL0 of 3AA HL2 of 3AI SL1 of 3AI HL2 of 3
  • ✓ you like proofs by contradiction and want a real use for one
  • ✓ you want to combine a proof with a simulation
  • ✓ you are curious how schools, hospitals or exchange programmes assign places

The big idea

A matching is stable if no student and school both prefer each other to their assigned partners. In the deferred acceptance method, free students propose down their lists and each school holds its best offer so far. It always stops, and the result is always stable. Both claims have short proofs, one by counting proposals and one by contradiction. Graph theory is AI HL content and the proofs suit AA HL, so both groups can use this topic with some self-study. The algorithm is routine. The marks come from the proofs and the simulation: why the proposing side gets its best stable outcome, and how the average number of proposals grows with the number of students.

Make it yours: pick one twist

Copying a classic won't show your choices. Pick one of these (or invent your own) and your IA becomes yours.

Swipe for more twists →

Prove it ends

Count the most proposals that can ever be made and show the algorithm must stop.

→ A counting argument: each student proposes to each school at most once, so there are at most n² proposals. Check it on a small case.
Prove it is stable

Suppose a blocking pair exists and show this contradicts the rule that schools only trade up.

→ A proof by contradiction written out in full, then tested on matchings found by brute force.
Who benefits: proposers or receivers?

Run the algorithm with students proposing, then with schools proposing, and compare the two stable matchings.

→ The proposing side gets its best possible stable partner for every member. Prove it by induction or find a counterexample to fairness.
Count the stable matchings

For small n, list all matchings and test each for stability to find how many are stable.

→ Exhaustive checking that links to counting principles. See how the number of stable matchings varies with the preferences.
Simulate proposals for random preferences

Generate random preference lists, run the algorithm, and record the number of proposals as n grows.

→ A simulation with a theoretical comparison, about n ln n. Find a reason using the coupon-collector problem.
Apply it to a real system

Model school or university place allocation, or a residency match, from published rules.

→ Real rules add quotas and ties. State what changes in the proofs and what does not.

Your Maths IA research question: run the check

who proposes, who ranks?

Write your own question first. Then make sure it ticks every box:

  • Names the matching problem: who proposes, who ranks, and how many on each side.
  • Says what is proved and what is simulated, and how the two are linked.
  • Defines stable precisely, with the condition for a blocking pair.
  • Says how random preferences are generated and how many trials each point uses.
  • States what is left out: ties, quotas, couples and strategic ranking.
Stuck on your question?Get an RQ Check: each question is scored on 5 points, with what to fix. Your first one is free.
Get an RQ Check

The model

Preference lists on both sides, the three steps of the method, and the one pattern that makes a matching unstable. Draw a small example of your own.

Preference listsS1: B > A > CA: S2 > S1 > S3S2: A > B > CB: S1 > S3 > S2S3: A > C > BC: S3 > S2 > S1studentsschoolsDeferred acceptance1 each free student proposes to the best school not yet tried2 each school keeps its best offer and rejects the rest3 repeat until nobody is freeoffers are held, not finalstpqmatched pairsblocking pair: s prefers q to p,and q prefers s to tstable = no blocking pair

How your Maths IA could be laid out

The usual order for a topic like this, what each part needs to show, and roughly how much of your 12 to 20 pages it takes. The words are all yours.

Aim and context~1 page
Where matching problems appear, what stable means, and a prediction before any proof.
The problem and the algorithm~2 pages
Preference lists, the deferred acceptance method and a worked example with every step shown.
It always ends~1.5 pages
A counting proof that the algorithm terminates, with the bound checked on your example.
It is always stable~2 pages
A proof by contradiction, written clearly, with a brute-force check on a small case.
Who gets the best outcome~2 pages
The proposers-optimal result, proved or tested, and what it means for fairness.
How many proposals?~3 pages
A simulation for several n with a comparison to n ln n and a reason for it.
Conclusion~1 page
Back to your aim: what you proved, what you measured and how well they agree.
Evaluation~2 pages, the biggest part!
Quotas, ties, honest ranking and real systems. Say which assumption a real school system breaks first.
Bibliographynot counted
Where the algorithm, proofs and rules came from.

What your Maths IA graph could look like

error bars, not just means

Made-up values to show the form of a strong graph: the average number of proposals against the number of students, with a theory curve. Yours will look different. example only

0204060801000100200300400500600Number of students n (count)Average proposals (count)n ln nyour simulation (made-up)points a little above n ln n:explain the gapILLUSTRATIVE · MADE-UP DATA
  • One point per n, each the mean of many simulated runs. Say how many.
  • Show spread, for example error bars of two standard errors, so the reader can see the noise.
  • Plot the theory curve on the same axes and say where it comes from.
  • If your points sit consistently above the curve, say why before the reader asks.

The maths in action

worked through, not sketched!

The graph above was a sketch with made-up numbers. This figure works the idea through from the model itself, so you can see what a finished figure looks like. The source line under it says where every number comes from.

Left: a bipartite graph of four students and four schools with a red matching and rank labels. Right: points rising with n, lying between a dashed curve n ln n and a dotted curve n H n.
(a) A 4-by-4 example: students propose (7 proposals); there are two stable matchings, and they differ for three students. (b) Average proposals for random preferences (400 runs per point) against n ln n: at n = 100 the mean is 496, 1.08 times n ln n.Source: Computed from the model (random preferences, seed fixed).

Your game plan

Tick steps off as you go. We'll remember on this device.

0 of 10 done

  1. Read and predictRead how the Gale-Shapley method works. Before any proof, guess how many proposals it takes for 4 students and 4 schools.
  2. Run a small caseMake preference lists for 4 students and 4 schools and run the method by hand, writing down every proposal.
  3. Check stability by brute forceList all 24 matchings of your small case and test each for a blocking pair. Compare with the algorithm's result.
  4. Trial run (1 lesson)Write the proof that the algorithm ends, and test the bound on your example. Fix the idea before the harder proof.
  5. Prove it is stableWrite the proof by contradiction. Say exactly which rule of the algorithm each step uses.
  6. Compare the two sidesRun the method with schools proposing. Compare the matchings and say who gains and who loses.
  7. Go further, with a reasonSimulate proposals for many n and compare with n ln n, or study quotas. HL: this is where the rigour for criterion E comes from.
  8. Explain the growthUse the coupon-collector idea to explain why proposals grow like n ln n, and say what the argument assumes.
  9. Reflect as you goAfter every result write one line on what it means for real admissions and what it assumes. These lines become your evaluation.
  10. Cut, check, then sendCheck every proof is complete, every symbol is defined once and the conclusion answers your aim. Then send your teacher one draft.

The maths you'll use

  • Counting proposals – Show every student proposes to each school at most once, so the algorithm stops after at most proposals.
  • Proof by contradiction – Assume a blocking pair exists and show it contradicts the rule that a school only trades up.
  • Proof by induction – Show no student is ever rejected by a partner that is stable for them, which gives the proposer-optimal result.
  • Expected value – Model proposals as a coupon-collector process to get as an upper bound on the expected number.
  • Simulation – Generate random preferences, run the algorithm and compare mean proposals with using standard errors.

Key equations

Syllabus links

  • 1.15Proof by induction, contradiction and counterexampleHL
  • 1.6Simple deductive proof
  • 4.7Discrete random variables and expected value

Read up first

Data and sources to start from

Simulate random preferences, and optionally compare with published rules of a real matching system such as a medical residency match.

References to cite

  1. Gale, D., & Shapley, L. S. (1962). College admissions and the stability of marriage. The American Mathematical Monthly, 69(1), 9-15.
  2. Knuth, D. E. (1997). Stable marriage and its relation to other combinatorial problems. American Mathematical Society.
  3. The Royal Swedish Academy of Sciences. (2012). The Prize in Economic Sciences 2012 [Press release and advanced information].
  4. Roth, A. E. (2015). Who gets what and why: The new economics of matchmaking and market design. Houghton Mifflin Harcourt.

Cite what you actually use, in your own format, and say where each number came from.

Traps to avoid in this Maths IA

an example is not a proof
  • Calling a matching 'best' without saying for whom. The method favours the proposing side.
  • Proving stability by example. An example is a check, not a proof.
  • Forgetting that a school may drop a held offer for a better one, so proposals are not decisions.
  • Using too few simulation runs and calling the curve a fit.
  • Claiming the average is exactly n ln n. Compare with the data and say how close it is.
  • Ignoring that real students can gain by ranking dishonestly under some rules.

More Maths IA ideas like this

Make sure it's yours

This guide shows how a topic like this is usually approached. It is not an IA. Your question, choices, data, analysis and words must be your own: change something, tell your teacher where the idea came from, and follow your school's rules on outside help.

Get your RQ checked · first one free