Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Sean Li CS 4820 Notes Spring 2013 Introduction to Design and Analysis of Algorithms Lecture 2 1/23/13 Homework 1: On CMS.

S. Stable Matching Problem (contd). Suppose we have two sets, say Employers (B for bosses) and Candidates (C). Each boss ranks candidates linearly, we write this b : c1 > c2 for each b B, and conversely, each candidate ranks the bosses linearly, we write this c : b1 > b2 for all c C. The denitions of matching, perfect, unstable, and stable are as in last lecture. Algorithm (Gale and Shapley, 1962). (The algorithm was actually being used up to 10 years before publication.) It satises the following properties. 1. Employers make oers to the candidates, always in decreasing order of preference. 2. At most one oer to each candidate. 3. Once a candidate is matched, she will never be unmatched. (Not true for employers.) 4. Candidates happiness only increases from changing employers. Algorithm. Proceed in stages, each being stable. Start with the empty matching, which is vacuously stable. At stage n, suppose we have a matching M . The (n + 1)-st stage is as follows. Let b be an unmatched employer. Let c be the candidate that b prefers the most and who b has not yet made an oer. Then b makes an oer to c. Now either c is matched or not matched. If c is not already matched, c accepts the oer from b. Now suppose c is already matched, say to b . If c : b > b, then c rejects the oer, and if c prefers b to b , then c chooses b, so M := (M (b , c)) + (b, c). Proof. This is guaranteed to terminate as each employer can make at most n oers, so the algorithm can run for at most n2 steps. Now suppose it terminates but there is an unmatched b. That would imply that there is an unmatched c, which contradicts that b has made an oer to every candidate. Thus it always halts with a perfect matching. Now to see why this is stable. Suppose an instability exists, then there exist (b1 , c1 ), (b2 , c2 ) M such that b2 : c1 > c2 and c1 : b2 > b1 . Then if b1 rst made an oer to c1 and then b2

made an oer to c1 , c1 would have switched to b2 , contradicting (b1 , c1 ) M . (Note that c1 could not have accepted an oer from a b3 that she prefers over b2 , else she would be matched with b3 .) And if b2 rst made an oer to c1 and then b1 made an oer to c1 , then c1 would have rejected the oer from b1 , again contradicting (b1 , c1 ) M . Note: There may exist perfect stable matchings that cannot be generated by this algorithm. Question: Given a denition of optimal happiness, is there an algorithm that maximizes it? Greedy Algorithms: Need to satisfy a global set of constraints, but decisions can be made locally without fear of messing something up for later. Methods of Analysis: Greedy stays ahead (GSA). Compare optimal solution with greedy solution, show greedy solution is as good. Exchange method. Take an optimal solution and show how to make little changes to it to turn into the greedy solution, without making it worse at any step. Applications: Shortest path (Dijkstra). Minimal spanning tree (Prim, Kruskal, etc.). Human code. Clustering.

Page 2

You might also like