Skip to content

Instantly share code, notes, and snippets.

@christopheragnus
Created June 20, 2019 07:16
Show Gist options
  • Save christopheragnus/916a06ce2442d09fc54f5420635ec1c6 to your computer and use it in GitHub Desktop.
Save christopheragnus/916a06ce2442d09fc54f5420635ec1c6 to your computer and use it in GitHub Desktop.
Gale-Shapley algorithm
function stableMatching {
Initialize all m ∈ M and w ∈ W to free
while ∃ free man m who still has a woman w to propose to {
w = first woman on m’s list to whom m has not yet proposed
if w is free
(m, w) become engaged
else some pair (m', w) already exists
if w prefers m to m'
m' becomes free
(m, w) become engaged
else
(m', w) remain engaged
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment