Animate the Gale-Shapley algorithm and explore stable matching step by step
Two groups rank each other. Can you pair everyone up so that no two people would rather be with each other than with their partners? Always.
Press Step to make one proposal at a time, or Run All to finish. Green marks current matches and red strikethroughs mark rejections; New Instance deals fresh preferences.
The stable matching problem asks: given two groups with ranked preferences over each other, can we find a matching where no pair would prefer to break their current matches to be together instead?
In 1962, David Gale and Lloyd Shapley proved the answer is always yes, and gave an elegant algorithm to find such a matching. Their work earned Shapley the 2012 Nobel Prize in Economics (shared with Alvin Roth, who applied the theory to real-world markets like medical residency matching and school choice).
Proposers (left) propose to their most preferred accepter who hasn't rejected them yet. Accepters hold the best proposal they've received and reject the rest.
Key insight: The algorithm always terminates with a stable matching. It is proposer-optimal — each proposer gets the best partner they could achieve in any stable matching.
Spot a mistake or have an idea?