Gale-Shapley Correctness
- The book does a nice job of stepping though the proof that this algorithm is correct.
- This is done in a series of statements and arguments.
- 1.1 Any woman w remains engaged from the point at which she receives her first proposal; and the sequence of partners to which she is engaged gets better and better (in terms of her preference list).
- The first part of this claim is easy. The only place a woman's status changes in the algorithm is line 7. It will never change.
- The second part is reasonably clear as well.
- Initially the partner is set in lines 6-7 where w is committed to man m.
- This will only be changed in lines 10-12, which will only be executed when the condition in line 5 is false (she is already committed) and the condition in line 8 is true (she prefers the new match to the old one).
- Thus she will never change to a less favorable match.
- 1.2 The sequence of women to whom m proposes gets worse and worse (in terms of his preference list)
- This is clear from line 4.
- Each time a man selects, he will select the most favored on his list.
- Each time he selects someone, he will remove that person from the list of those who are eligible for selection in the future.
- 1.3 The Gale-Shapley algorithm terminates after at most $n^2$ iterations of the while loop.
- There are n men and n women, so there is a total of $n^2$ entries in the preference list.
- Each of the n men have a list.
- Each list contains n women.
- Line 4 will execute each iteration of the while loop
- And at each execution one name will be removed from their list.
- Therefore the while loop in line 2 can only execute $O(n^2)$ times.
- 1.4 If a man m is free at some point, then there is a woman to whom he has not yet proposed.
- This proof is done by contradiction.
- Assume that there as some man m who is free but has proposed to all women.
- This means that every woman is currently engaged to some other man. (By 1.1)
- But there are n women and n-1 other men.
- So there must be some woman who is not engaged.
- Thus the assumption is false.
- 1.5 The set S returned at termination of the Gale-Shapley algorithm is a perfect match.
- Assume that the algorithm terminates with a man m free.
- For the algorithm to terminate (loop in line 2) he must have proposed to every woman.
- But this contradicts the previous claim (1.4)
- Therefore the algorithm can not terminate with a man free, all men are paired with some woman.
- It is clear from lines 6-7 and 10-12 that a woman will only ever be engaged to one man
- Therefore since all n men are engaged, and there are only n women, each of whom is engaged to a different man, the match is perfect.
- 1.6 Consider an execution of the Gale-Shapley algorithm that returns a stet of pairs S. The set S is a stable matching.
- To be a stable matching the match must be
- Perfect, which was proven in 1.5
- Have no instable pairings.
- Assume that (m, w) ∈ S and (m', w') ∈ S represent an instablity.
- This means m prefers w' to w
- And w' prefers m to m'
- Since these are in S, then the last accepted proposal in the execution of the algorithm by m was to w.
- But since m prefers w' to w, he must have proposed to w' at some point earlier in the execution (line 4).
- This means at that point m was rejected by w' for some more preferable man m'' (1.1)
- Since w' prefers m to m', m'' can not be m', the man who w' is paired with.
- Which is a contradiction, thus the statement is true.