CS 70
Discrete Mathematics for CS
Spring 2008
David Wagner
Note 7
Stable Marriage — An Application of Proof Techniques to
Algorithmic Analysis
Consider a dating agency that must match up
n
men and
n
women. Each man has an ordered
preference
list
of the
n
women, and each woman has a similar list of the
n
men (ties are not allowed). Is there a good
algorithm that the agency can use to determine a good pairing?
Example
Consider for example
n
=
3 men (represented by numbers 1, 2, and 3) and 3 women (
A
,
B
, and
C
), and the
following preference lists:
Men
Women
1
A
B
C
2
B
A
C
3
A
B
C
Women
Men
A
2
1
3
B
1
2
3
C
1
2
3
For instance, the preference lists above mean that woman
A
is man 1’s top choice; woman
B
is his second
choice; and so on.
What properties should a good pairing have? One possible criterion for a “good” pairing is one in which the
number of first ranked choices is maximized. Another possibility is to minimize the number of last ranked
choices. Or perhaps minimizing the sum of the ranks of the choices, which may be thought of as maximizing
the average happiness. In this lecture we will focus on a very basic criterion:
stability
. A pairing is unstable
if there is a man and a woman who prefer each other to their current partners. We will call such a pair a
rogue couple
. So a pairing of
n
men and
n
women is stable if it has no rogue couples.
An unstable pairing from the above example is:
{
(
1
,
C
)
,
(
2
,
B
)
,
(
3
,
A
)
}
. The reason is that 1 and
B
form a
rogue couple, since 1 would rather be with
B
than
C
(his current partner), and since
B
would rather be with
1 than 2 (her current partner). This is trouble: Before long, 1 and
B
are going to spending many late nights
doing CS70 problem sets together. Obviously, the existence of rogue couples is not a good thing if you are
a matchmaker, since they will lead to instability or customer dissatisfaction. That is why we focus on stable
pairings.
An example of a stable pairing is:
{
(
2
,
A
)
,
(
1
,
B
)
,
(
3
,
C
)
}
. Note that
(
1
,
A
)
is not a rogue couple. It is true
that man 1 would rather be with woman
A
than his current partner. Unfortunately for him, she would rather
be with her current partner than with him. Note also that both 3 and
C
are paired with their least favorite
choice in this matching. Nonetheless, it is a stable pairing, since there are no rogue couples.
The problem facing us is to find a stable pairing, given the preference lists for all
n
men and all
n
women.
CS 70, Spring 2008, Note 7
1