On this page
Four students, four colleges, one seat each, and everyone has ranked the other side. David Gale and Lloyd Shapley showed how to fill the seats so nobody wants to break the deal, in their 1962 paper College Admissions and the Stability of Marriage.
What problem does stable matching solve?
A matching is stable when no student and college would both prefer each other to the partners they got. Such a pair is a blocking pair. Hall's marriage theorem asks whether everyone can be matched at all; Gale–Shapley asks whether they can be matched so nobody wants to break away.
Preferences, best first:
Asha: P, Q, R, S
Bilal: Q, P, S, R
Chitra: P, R, Q, S
Dev: Q, R, S, P
College P: Bilal, Asha, Chitra, Dev
College Q: Asha, Bilal, Dev, Chitra
College R: Dev, Chitra, Asha, Bilal
College S: Chitra, Dev, Bilal, Asha
How does the Gale–Shapley algorithm work, step by step?
The rules fit in three lines:
Every student without a seat applies to the highest college on their list that has not yet rejected them.
Each college holds the best applicant it has seen so far, including anyone it was already holding, and rejects the rest.
Repeat until a round passes with no rejections.
Now run it with students proposing:
Round 1: Asha and Chitra apply to P; Bilal and Dev apply to Q. P prefers Asha and rejects Chitra. Q holds Bilal and rejects Dev.
Round 2: Chitra and Dev both apply to R, their second choice. R ranks Dev first, so it holds Dev and rejects Chitra.
Round 3: Chitra tries Q, which prefers Bilal, so she is rejected again.
Round 4: Chitra applies to S, which is empty and holds her. Nobody is rejected, so the algorithm stops.
Result: Asha with P, Bilal with Q, Chitra with S, Dev with R, after eight applications and four rejections.
Why does it always end in a stable matching?
First, it always finishes. Each student applies to each college at most once, so n students and n colleges need at most n × n applications: here at most 16, and we used 8. As the Wikipedia article on the algorithm notes, it can be implemented to run in time quadratic in the number of participants.
Second, everyone gets a seat. A college that has received an application is never empty again. If a student were rejected by all four colleges, all four would be holding someone, but only three other students exist. It is the kind of counting you meet in counting arguments with bijections.
Third, no blocking pair survives. Take Chitra, who ranks P above her seat at S. She applied to P before S, and P rejected her only for someone it liked more. P's choice only improves after that, so P ends with someone it ranks above Chitra, and the pair does not block. The same check works for every pair.
If arguments like this feel slippery, the Fermi Concept Library has a lesson for each concept in mathematics and computing.
Why does the proposing side do better?
Now let colleges apply instead. In round 1, P picks Bilal, Q picks Asha, R picks Dev and S picks Chitra. Nobody is rejected, so it stops at once: Asha with Q, Bilal with P, Chitra with S, Dev with R. This is also stable, because every college got its first choice.
When students propose, Asha and Bilal each get their first choice; when colleges propose, each gets their second. Colleges P and Q see the reverse. In general, the result is the best stable outcome for the side that proposes and the worst for the side that receives, as the same Wikipedia article sets out. Asking who gains under a set of rules is game theory, which you also meet in the prisoner's dilemma.
Where is the Gale–Shapley algorithm used in real life?
US medical residency: the National Resident Matching Program says its matching algorithm is applicant-proposing, so the rule above suggests the outcome leans towards applicants.
In 1984 Alvin Roth observed that essentially the same algorithm had been in practical use for that match since the early 1950s, and Shapley and Roth shared the 2012 economics Nobel "for the theory of stable allocations and the practice of market design" (source).
School places: Atila Abdulkadiroğlu, Parag Pathak and Alvin Roth described the New York City high school match in 2005.
Indian engineering admissions: researchers from three IITs and Columbia designed a process based on deferred acceptance for undergraduate admissions to over 500 programmes at 80 technical universities.
Try it yourself
Change College R's list to Chitra, Dev, Asha, Bilal and rerun with students proposing. You should get Asha with P, Bilal with Q, Chitra with R and Dev with S, in three rounds.
Check stability: test each student against every college they rank above their match.
For more practice, the Fermi Problem Library has a step-by-step solver that explains the reasoning rather than printing an answer.



