
Data Structures and Algorithms - COMS21103
Stable Matching and Dijkstra’s Algorithm Problem Sheet
A: Stable Matching A quick overview of the Gale-Shapley algorithm. For n
men (m1, m2, . . . mn) and nwomen (w1, w2, . . . wn) each with strict preference
lists.
1. Let ibe the smallest value such that miis unmatched.
2. miproposes to the most desirable woman (according to his list) that hasn’t
already rejected him.
3. She accepts if either a) she is unmatched or b) she finds mimore desirable
than her current match (who becomes unmatched).
4. Repeated until all men are matched.
Lemma 1. The Gale-Shapley algorithm with the men as proposers gives the
worst possible valid partner for each woman.
1. Prove Lemma 1.
Lemma 2. The Gale-Shapley algorithm always gives the best possible valid pair-
ing for each man.
2. Use the statement and proof (given in lectures) of Lemma 2 to show that
the Gale-Shapley algorithm gives the same matching regardless of how the
next unmatched man to be considered is picked (this is step 1 above).
3. Show how to choose suitable data structures for the Gale-Shapley algo-
rithm so that its running time is O(n2). You can assume there are n
women and nmen to be matched.
4. Consider the ‘stable roommate’ problem where n people rank each other
in order of preference (assume n is even). The task is to pair up the
people in a perfect matching as in the stable matching problem shown in
lectures but this time there are no genders. That is anyone can match with
anyone else. Give an example where there is no stable matching possible
and explain why this is the case.
We now consider an extension of the stable matching problem to include
‘good’ and ‘bad’ people. The town has nmen and nwomen all with preference
lists as before. Further assume that there are k‘good’ men and k‘good’ women.
Anyone not ‘good’ is ‘bad’. We are told that each man (woman) would rather
marry a ‘good’ woman (man) than any ‘bad’ woman (man).
5. Show that in every stable matching, every good man is married to a good
woman.
1