0% found this document useful (0 votes)
14 views2 pages

A First Problem

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

A First Problem

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

A first problem: Stable matching

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

A perfect matching is a matching of men and women in which everyone is matched


monogamously. Each man gets exactly one woman, and each woman gets exactly one man.

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

Let's consider a simple example with 3 men and 3 women:

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

The resultant Matching is :


{A Z},{B X},{C Y}
Time complexity
This algorithm takes O(n2) time where n is the number of men/women.
In the worst case, all men will be engaged with their least preferred choice, so we make n
iterations for each man
Therefore, in the worst case scenario, we make a total of n * n iterations and as m = w = n ,
time complexity becomes O(n2).

You might also like