Algorithm Design Soution Manual By Jon Kleinberg Eva Tardos ,Pass With
Grade A+
Stable Matching f d
Note: Exercises denoted with an asterisk ∗( ) tend to be more difficult, or to rely on some
f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d f
of the more advanced material.
d fd fd fd fd
1. Gale and Shapley published their paper on the stable marriage problem in 1962; but a vers
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
ion of their algorithm had already been in use for ten years by the National Resident Matc
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
hing Program, for the problem of assigning medical residents to hospitals.
f d f d f d f d f d f d f d f d f d f d
Basically, the situation was the following. There were m hospitals, each with a certain nu
fd fd fd fd fd f d fd fd fd fd fd fd fd fd
mber of available positions for hiring residents. There were n medical students graduatin
fd fd fd fd fd fd f d fd fd fd fd fd
g in a given year, each interested in joining one of the hospitals. Each hospital had a rank
fd fd fd fd fd fd fd fd fd fd fd fd f d fd fd f d f d
ing of the students in order of preference, and each student had a ranking of the
f d f d f d f d f d f d f d f d f d f d f d f d f d fd fd fd
hospitals in order of preference. We will assume that there were more students graduati
fd fd fd fd f d fd fd fd fd fd fd fd fd
ng than there were slots available in the m hospitals.
f d f d f d f d f d f d f d f d f d
The interest, naturally, was in finding a way of assigning each student to at most one hospi
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
tal, in such a way that all available positions in all hospitals were filled. (Since
f d f d f d f d f d f d f d f d f d f d f d f d f d f d fd
we are assuming a surplus of students, there would be some students who do not get assi
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
gned to any hospital.) fd fd fd
We say that an assignment of students to hospitals is stable if neither of the following situ
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
ations arises. fd
• First type of instability: There are students s and sr , and a hospital h, so that
fd fd fd f d fd fd fd fd fd fd f d fd fd fd fd fd
– s is assigned to h, and
fd fd fd fd fd
– sr is assigned to no hospital, and
f d f d f d f d f d f d
– h prefers sr to s. fd fd f d fd
r r
• Second type of instability: There are students s and s , and hospitals h and h ,
f d f d f d f d f d f d f d f d f d fd f d f d f d f d f d fd
so that fd
– s is assigned to h, and
fd fd fd fd fd
– sr is assigned to hr, and
f d f d f d f d f d
– h prefers sr to s, and
f d f d f d f d f d
– sr prefers h to hr.
f d fd fd fd
So we basically have the stable marriage problem from class, except that (i) hospitals gene
fd fd fd fd fd fd fd fd fd fd fd fd fd fd
rally want more than one resident, and (ii) there is a surplus of medical students.
f d f d f d f d f d f d f d f d f d f d f d f d f d f d
Show that there is always a stable assignment of students to hospitals, and give an efficien
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
1
,t algorithm to find one. The input size is Θ(mn); ideally, you would like to find an
f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d fd f
dalgorithm with this running time.
f d f d f d f d
Solution. The algorithm is very similar to the one from class. At any point in ti
f d f d fd fd fd fd fd fd fd fd fd f d fd fd fd fd
me, a student is either “committed” to a hospital or “free.” A hospital either has avail
fd fd fd fd fd fd fd fd fd fd f d fd fd fd fd
able positions, or it is “full.” The algorithm is the following:
fd fd fd fd fd f d fd fd fd fd
2
, While some hospital hi has available positions hi offers a position to the next st
fd fd fd fd fd fd fd fd fd fd fd fd fd fd
udent sj on its preference list if sj is free then sj accepts the offer else (sj is a
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
lready committed to a hospital hk) if sj prefers hk to hi then sj remains com
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
mitted to hk else sj becomes committed to hi the number of available positi
fd fd fd fd fd fd fd fd fd fd fd fd fd
ons at hk increases by one. the number of available positions at hi decrease
fd fd fd fd fd f d fd fd fd fd fd fd fd
s by one. fd fd
The algorithm terminates in O(mn) steps because each hospital offers a positions
f d f d f d f d f d f d f d f d f d f d f d f
dto a student at most once, and in each iteration, some hospital offers a position to some
f d fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
student.
Suppose there are pi > 0 positions available at hospital hi. The algorithm terminates w
fd fd fd fd fd fd fd fd fd fd f d fd fd fd
ith an assignment in which all available positions are filled, because any hospital that did
fd fd fd fd fd fd fd fd fd fd fd fd fd fd
not fill all its positions must have offered one to every student; but then, all these stu
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
dents would be committed to some hospital, which contradicts our assumption that
Σm i
fd fd fd fd fd fd fd fd fd fd fd
=1 pi < n.
fd
fd fd
Finally, we want to argue that the assignment is stable. For the first kind of instability,
fd fd fd fd fd fd fd fd fd f d fd fd fd fd fd fd
suppose there are students s and sr, and a hospital h as above. If h prefers sr to s, the
fd fd fd fd fd fd fd fd fd fd fd fd f d fd fd fd fd fd fd
n h would have offered a position to sr before it offered one to s; from then on, sr wou
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
ld have a position at some hospital, and hence would not be free at the end —
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
a contradiction.
fd fd
For the second kind of instability, suppose that (hi, sj) is a pair that causes instability. T
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
hen hi must have offered a position to sj, for otherwise it has pi residents all of who
fd f d fd fd fd fd fd fd fd fd fd fd fd f d fd fd fd
m it prefers to sj. Moreover, sj must have rejected hi in favor of some hk which he/she
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
preferred; and sj must therefore be committed to some hl (possibly different from hk) whi
fd fd fd fd fd fd fd fd fd fd fd fd fd fd
ch he/she also prefers to hi.
fd fd fd fd fd
2. We can think about a different generalization of the stable matching problem, in which cer
fd fd fd fd fd fd fd fd fd fd fd fd fd fd
tain man-woman pairs are explicitly forbidden. In the case of employers and ap-
fd fd fd fd fd f d fd fd fd fd fd fd
plicants, picture that certain applicants simply lack the necessary qualifications or degr
fd f d fd fd fd fd fd fd fd fd fd f d
ee; and so they cannot be employed at certain companies, however desirable they may s
fd fd fd fd fd fd fd fd fd fd fd fd fd f d
eem. Concretely, we have a set M of n men, a set W of n women, and a se
f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d
t F ⊆ M × W of pairs who are simply not allowed to get married. Each man
fd f d fd f d fd f d f d f d f d f d f d f d f d f d f d f d f d f d
m ranks all the women w for which (m, w) /∈ F , and each woman wr ranks all the men mr
f d fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
for which (mr, wr) /∈ F .
fd f d fd fd fd fd
In this more general setting, we say that a matching S is stable if it does not exhibit an
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
y of the following types of instability.
fd fd fd fd fd fd
(i) There are two pairs (m, w) and (mr, wr) in S with the property that m prefers wr
fd fd fd fd fd fd fd fd fd fd f d fd fd fd fd fd fd
to w, and wr prefers m to mr. (The usual kind of instability.)
f d f d f d f d f d f d f d f d f d f d f d f d
(ii) There is a pair (m, w) ∈S, and a man mr, so that mr is not part of any pair in the m
fd fd fd fd fd f d f d fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
atching, (mr, w) F/∈, and w prefers mr to m. (A single man is more desirable an fd fd f d fd fd fd fd fd fd fd fd fd fd fd fd fd fd
d not forbidden.) fd fd
3
, (iir) There is a pair (m, w) ∈ S, and a woman wr, so that wr is not part of an
f d f d f d f d f d fd f d f d f d f d f d f d f d f d f d f d f d f d f d f d
y pair in the matching, (m,/∈wr) F , and m prefers wr to w. (A single woman is mo
f d fd fd fd fd fd f d fd fd fd fd fd fd fd fd fd fd fd fd
re desirable and not forbidden.) fd fd fd fd
(iii) There is a man m and a woman w, neither of which is part of any pair in the m
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
atching, so that (m, w) F . /∈
(There are two single people with nothing prevent- fd fd fd fd fd fd fd fd fd fd fd fd fd fd
ing them from getting married to each other.)
fd fd fd fd fd fd fd fd
Note that under these more general definitions, a stable matching need not be a perfect
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
matching.
Now we can ask: for every set of preference lists and every set of forbidden pairs, is ther
fd fd fd f d fd fd fd fd fd fd fd fd fd fd fd fd f d
e always a stable matching? Resolve this question by doing one of the followin
f d f d f d f d f d f d f d f d f d f d f d f d f d
g two things: (a) Giving an algorithm that, for any set of preference lists and forbidden pai
fd fd f d fd fd fd fd fd fd fd fd fd fd fd fd fd
rs, produces a stable matching; or (b) Giving an example of a set of preference lists and f
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd f d f d
orbidden pairs for which there is no stable matching. f d f d f d f d f d f d f d f d
Solution. There is always a stable matching, even in the general model with forbidden p
f d fd fd fd fd fd fd fd fd fd fd fd fd fd
airs. The most direct way to prove this is through an algorithm that is almost the sam
f d fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
e as the one we used for the basic stable matching problem in class; indeed, the only
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
change is that our condition for the While loop will say: “While there is a man m
fd fd fd fd fd fd fd fd fd fd f d fd fd fd fd fd fd
who is free and hasn’t proposed to every woman w for which (m, w) F .”/∈ Here is the
fd fd fd fd fd fd fd fd fd fd fd fd fd f d f d fd f d fd fd fd
algorithm in full: fd fd
Initially all m ∈ M and w∈ W are free While there is a man m w
f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d
ho is free and hasn’t proposed to every woman w for which/∈ (m, w)
f d fd f d f d f d f d f d f d f d f d f d f d fd f d f d
F Choose such a man m Let w be the highest-
f d fd f d f d f d f d f d f d f d f d
ranked woman in m’s preference list to which m has not yet proposed
f d f d f d f d f d fd f d f d f d f d f d f d f
dIf w is free then (m, w) become engaged Else w is currently engaged to m
f d f d f d f d f d fd f d f d fd fd f d fd fd fd fd
r If w prefers mr to m then m remains free Else w prefers m to mr (m, w) beco
f d fd f d fd f d fd fd fd fd fd fd fd fd fd fd fd fd fd fd
me engaged mr becomes free Endif Endif Endwhile Return the set S of eng
fd fd fd fd fd fd fd f d f d f d f d f d f d
aged pairs f d
Now, facts (1.1) - fd fd fd
(1.3) from the book remain true; and we don’t have to worry about establishing that t
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
he resulting matching S is perfect (indeed, it may not be). We also notice an additiona
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
l pairs of facts. If m is a man who is not part of a pair in S, then m must have pro
fd fd fd f d fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
posed to every non- fd fd fd
forbidden woman; and if w is a woman who is not part of a pair in S, then it must be that
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
no man ever proposed to w.
fd fd fd fd fd fd
Finally, we need only show f d f d f d f d
• There is no instability with respect to the returned matching S.
fd fd fd fd fd fd fd fd fd fd
Our general definition of instability has four parts; this means that we have to
f d f d f d f d f d f d f d f d f d f d f d f d f d f d
make sure none of the four bad things happens.
fd fd fd fd fd fd fd fd
First, suppose that there is an instability of type (i), consisting of pairs (m, w)
f d f d f d f d f d f d f d f d f d f d f d f d f d fd f d
4
Grade A+
Stable Matching f d
Note: Exercises denoted with an asterisk ∗( ) tend to be more difficult, or to rely on some
f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d f
of the more advanced material.
d fd fd fd fd
1. Gale and Shapley published their paper on the stable marriage problem in 1962; but a vers
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
ion of their algorithm had already been in use for ten years by the National Resident Matc
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
hing Program, for the problem of assigning medical residents to hospitals.
f d f d f d f d f d f d f d f d f d f d
Basically, the situation was the following. There were m hospitals, each with a certain nu
fd fd fd fd fd f d fd fd fd fd fd fd fd fd
mber of available positions for hiring residents. There were n medical students graduatin
fd fd fd fd fd fd f d fd fd fd fd fd
g in a given year, each interested in joining one of the hospitals. Each hospital had a rank
fd fd fd fd fd fd fd fd fd fd fd fd f d fd fd f d f d
ing of the students in order of preference, and each student had a ranking of the
f d f d f d f d f d f d f d f d f d f d f d f d f d fd fd fd
hospitals in order of preference. We will assume that there were more students graduati
fd fd fd fd f d fd fd fd fd fd fd fd fd
ng than there were slots available in the m hospitals.
f d f d f d f d f d f d f d f d f d
The interest, naturally, was in finding a way of assigning each student to at most one hospi
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
tal, in such a way that all available positions in all hospitals were filled. (Since
f d f d f d f d f d f d f d f d f d f d f d f d f d f d fd
we are assuming a surplus of students, there would be some students who do not get assi
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
gned to any hospital.) fd fd fd
We say that an assignment of students to hospitals is stable if neither of the following situ
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
ations arises. fd
• First type of instability: There are students s and sr , and a hospital h, so that
fd fd fd f d fd fd fd fd fd fd f d fd fd fd fd fd
– s is assigned to h, and
fd fd fd fd fd
– sr is assigned to no hospital, and
f d f d f d f d f d f d
– h prefers sr to s. fd fd f d fd
r r
• Second type of instability: There are students s and s , and hospitals h and h ,
f d f d f d f d f d f d f d f d f d fd f d f d f d f d f d fd
so that fd
– s is assigned to h, and
fd fd fd fd fd
– sr is assigned to hr, and
f d f d f d f d f d
– h prefers sr to s, and
f d f d f d f d f d
– sr prefers h to hr.
f d fd fd fd
So we basically have the stable marriage problem from class, except that (i) hospitals gene
fd fd fd fd fd fd fd fd fd fd fd fd fd fd
rally want more than one resident, and (ii) there is a surplus of medical students.
f d f d f d f d f d f d f d f d f d f d f d f d f d f d
Show that there is always a stable assignment of students to hospitals, and give an efficien
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
1
,t algorithm to find one. The input size is Θ(mn); ideally, you would like to find an
f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d fd f
dalgorithm with this running time.
f d f d f d f d
Solution. The algorithm is very similar to the one from class. At any point in ti
f d f d fd fd fd fd fd fd fd fd fd f d fd fd fd fd
me, a student is either “committed” to a hospital or “free.” A hospital either has avail
fd fd fd fd fd fd fd fd fd fd f d fd fd fd fd
able positions, or it is “full.” The algorithm is the following:
fd fd fd fd fd f d fd fd fd fd
2
, While some hospital hi has available positions hi offers a position to the next st
fd fd fd fd fd fd fd fd fd fd fd fd fd fd
udent sj on its preference list if sj is free then sj accepts the offer else (sj is a
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
lready committed to a hospital hk) if sj prefers hk to hi then sj remains com
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
mitted to hk else sj becomes committed to hi the number of available positi
fd fd fd fd fd fd fd fd fd fd fd fd fd
ons at hk increases by one. the number of available positions at hi decrease
fd fd fd fd fd f d fd fd fd fd fd fd fd
s by one. fd fd
The algorithm terminates in O(mn) steps because each hospital offers a positions
f d f d f d f d f d f d f d f d f d f d f d f
dto a student at most once, and in each iteration, some hospital offers a position to some
f d fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
student.
Suppose there are pi > 0 positions available at hospital hi. The algorithm terminates w
fd fd fd fd fd fd fd fd fd fd f d fd fd fd
ith an assignment in which all available positions are filled, because any hospital that did
fd fd fd fd fd fd fd fd fd fd fd fd fd fd
not fill all its positions must have offered one to every student; but then, all these stu
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
dents would be committed to some hospital, which contradicts our assumption that
Σm i
fd fd fd fd fd fd fd fd fd fd fd
=1 pi < n.
fd
fd fd
Finally, we want to argue that the assignment is stable. For the first kind of instability,
fd fd fd fd fd fd fd fd fd f d fd fd fd fd fd fd
suppose there are students s and sr, and a hospital h as above. If h prefers sr to s, the
fd fd fd fd fd fd fd fd fd fd fd fd f d fd fd fd fd fd fd
n h would have offered a position to sr before it offered one to s; from then on, sr wou
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
ld have a position at some hospital, and hence would not be free at the end —
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
a contradiction.
fd fd
For the second kind of instability, suppose that (hi, sj) is a pair that causes instability. T
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
hen hi must have offered a position to sj, for otherwise it has pi residents all of who
fd f d fd fd fd fd fd fd fd fd fd fd fd f d fd fd fd
m it prefers to sj. Moreover, sj must have rejected hi in favor of some hk which he/she
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
preferred; and sj must therefore be committed to some hl (possibly different from hk) whi
fd fd fd fd fd fd fd fd fd fd fd fd fd fd
ch he/she also prefers to hi.
fd fd fd fd fd
2. We can think about a different generalization of the stable matching problem, in which cer
fd fd fd fd fd fd fd fd fd fd fd fd fd fd
tain man-woman pairs are explicitly forbidden. In the case of employers and ap-
fd fd fd fd fd f d fd fd fd fd fd fd
plicants, picture that certain applicants simply lack the necessary qualifications or degr
fd f d fd fd fd fd fd fd fd fd fd f d
ee; and so they cannot be employed at certain companies, however desirable they may s
fd fd fd fd fd fd fd fd fd fd fd fd fd f d
eem. Concretely, we have a set M of n men, a set W of n women, and a se
f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d
t F ⊆ M × W of pairs who are simply not allowed to get married. Each man
fd f d fd f d fd f d f d f d f d f d f d f d f d f d f d f d f d f d
m ranks all the women w for which (m, w) /∈ F , and each woman wr ranks all the men mr
f d fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
for which (mr, wr) /∈ F .
fd f d fd fd fd fd
In this more general setting, we say that a matching S is stable if it does not exhibit an
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
y of the following types of instability.
fd fd fd fd fd fd
(i) There are two pairs (m, w) and (mr, wr) in S with the property that m prefers wr
fd fd fd fd fd fd fd fd fd fd f d fd fd fd fd fd fd
to w, and wr prefers m to mr. (The usual kind of instability.)
f d f d f d f d f d f d f d f d f d f d f d f d
(ii) There is a pair (m, w) ∈S, and a man mr, so that mr is not part of any pair in the m
fd fd fd fd fd f d f d fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
atching, (mr, w) F/∈, and w prefers mr to m. (A single man is more desirable an fd fd f d fd fd fd fd fd fd fd fd fd fd fd fd fd fd
d not forbidden.) fd fd
3
, (iir) There is a pair (m, w) ∈ S, and a woman wr, so that wr is not part of an
f d f d f d f d f d fd f d f d f d f d f d f d f d f d f d f d f d f d f d f d
y pair in the matching, (m,/∈wr) F , and m prefers wr to w. (A single woman is mo
f d fd fd fd fd fd f d fd fd fd fd fd fd fd fd fd fd fd fd
re desirable and not forbidden.) fd fd fd fd
(iii) There is a man m and a woman w, neither of which is part of any pair in the m
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
atching, so that (m, w) F . /∈
(There are two single people with nothing prevent- fd fd fd fd fd fd fd fd fd fd fd fd fd fd
ing them from getting married to each other.)
fd fd fd fd fd fd fd fd
Note that under these more general definitions, a stable matching need not be a perfect
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
matching.
Now we can ask: for every set of preference lists and every set of forbidden pairs, is ther
fd fd fd f d fd fd fd fd fd fd fd fd fd fd fd fd f d
e always a stable matching? Resolve this question by doing one of the followin
f d f d f d f d f d f d f d f d f d f d f d f d f d
g two things: (a) Giving an algorithm that, for any set of preference lists and forbidden pai
fd fd f d fd fd fd fd fd fd fd fd fd fd fd fd fd
rs, produces a stable matching; or (b) Giving an example of a set of preference lists and f
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd f d f d
orbidden pairs for which there is no stable matching. f d f d f d f d f d f d f d f d
Solution. There is always a stable matching, even in the general model with forbidden p
f d fd fd fd fd fd fd fd fd fd fd fd fd fd
airs. The most direct way to prove this is through an algorithm that is almost the sam
f d fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
e as the one we used for the basic stable matching problem in class; indeed, the only
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
change is that our condition for the While loop will say: “While there is a man m
fd fd fd fd fd fd fd fd fd fd f d fd fd fd fd fd fd
who is free and hasn’t proposed to every woman w for which (m, w) F .”/∈ Here is the
fd fd fd fd fd fd fd fd fd fd fd fd fd f d f d fd f d fd fd fd
algorithm in full: fd fd
Initially all m ∈ M and w∈ W are free While there is a man m w
f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d f d
ho is free and hasn’t proposed to every woman w for which/∈ (m, w)
f d fd f d f d f d f d f d f d f d f d f d f d fd f d f d
F Choose such a man m Let w be the highest-
f d fd f d f d f d f d f d f d f d f d
ranked woman in m’s preference list to which m has not yet proposed
f d f d f d f d f d fd f d f d f d f d f d f d f
dIf w is free then (m, w) become engaged Else w is currently engaged to m
f d f d f d f d f d fd f d f d fd fd f d fd fd fd fd
r If w prefers mr to m then m remains free Else w prefers m to mr (m, w) beco
f d fd f d fd f d fd fd fd fd fd fd fd fd fd fd fd fd fd fd
me engaged mr becomes free Endif Endif Endwhile Return the set S of eng
fd fd fd fd fd fd fd f d f d f d f d f d f d
aged pairs f d
Now, facts (1.1) - fd fd fd
(1.3) from the book remain true; and we don’t have to worry about establishing that t
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
he resulting matching S is perfect (indeed, it may not be). We also notice an additiona
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
l pairs of facts. If m is a man who is not part of a pair in S, then m must have pro
fd fd fd f d fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
posed to every non- fd fd fd
forbidden woman; and if w is a woman who is not part of a pair in S, then it must be that
fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
no man ever proposed to w.
fd fd fd fd fd fd
Finally, we need only show f d f d f d f d
• There is no instability with respect to the returned matching S.
fd fd fd fd fd fd fd fd fd fd
Our general definition of instability has four parts; this means that we have to
f d f d f d f d f d f d f d f d f d f d f d f d f d f d
make sure none of the four bad things happens.
fd fd fd fd fd fd fd fd
First, suppose that there is an instability of type (i), consisting of pairs (m, w)
f d f d f d f d f d f d f d f d f d f d f d f d f d fd f d
4