A First Problem
A First Problem
The Gale-Shapley algorithm, also known as the Deferred Acceptance algorithm, is used to
solve the Stable Matching Problem. It was introduced by David Gale and Lloyd Shapley in
1962. The goal is to find a stable matching between two equally sized sets of elements, where
each element has a preference list ranking the elements of the other set.
Perfect Matching
Unstable Pairs
In a matching A, an unmatched pair M-W is unstable if man M and woman W prefer each
other to their current partners.
Let us consider there are two men, M1 and M2, and two women, W1 and W2.
Let M1's list of preference is {W1, W2}
Let m2's list of preference is {W1, W2}
Let w1's list of preference is {M1, M2}
Let w2's list of preference is {M1, M2}
The matching { {M1, W2}, {W1, M2} } isn’t stable because M1 and W1 prefers each other
over their current assigned partners.
The matches {M1, W1} and {M2, W2} are stable because no two people of the opposite sex
would prefer each other over their assigned partners.
Algorithm
Initialize all men and women to free
while there exist a free man m who still has a woman w to propose to
{
w = m's highest ranked such woman to whom he 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, w) become engaged
m' becomes free
else
(m', w) remain engaged
}
Example
Preference Lists:
Men:
oA: X, Y, Z
oB: X, Z, Y
oC: Y, Z, X
Women:
o X: B, A, C
o Y: B, C, A
o Z: C, A, B