CS 401: Computer Algorithms I Stable Matching Xiaorui Sun 1
Administrativia Stuffs • Website: http://www.cs.uic.edu/~xiaorui/cs401 • Lecture slides, homework • Piazza: piazza.com/uic/fall2020/2020fallcs40141675 • Announcements, online discussion forum • TA will answer course related questions • Homework/Exam submission: https://www.gradescope.com/courses/169509 • Homework 0 posted (due September 9) Calm down, just test GradeScope • Office hours on Blackboard Collaborate: • Myself: Fri 2pm-4pm • TA Wenyu Jin: Tue 10am-12pm 2
Last Lecture (summary) Stable matching problem: Given n men and n women, and their preferences, find a stable matching. For a perfect matching M , a pair m-w is unstable if they prefer each other to their match in M. least favorite favorite least favorite favorite 1 st 2 nd 3 rd 1 st 2 nd 3 rd Xavier Amy Brenda Claire Amy Yuri Xavier Zoran Yuri Brenda Amy Claire Brenda Xavier Yuri Zoran Zoran Amy Brenda Claire Claire Xavier Yuri Zoran Men’s Preference Profile Women’s Preference Profile Q: Is Yuri-Brenda an unstable pair? A: No, Yuri and Brenda get matched. 3
Last Lecture (summary) Stable matching problem: Given n men and n women, and their preferences, find a stable matching. For a perfect matching M , a pair m-w is unstable if they prefer each other to their match in M. least favorite favorite least favorite favorite 1 st 2 nd 3 rd 1 st 2 nd 3 rd Xavier Amy Brenda Claire Amy Yuri Xavier Zoran Yuri Brenda Amy Claire Brenda Xavier Yuri Zoran Zoran Amy Brenda Claire Claire Xavier Yuri Zoran Men’s Preference Profile Women’s Preference Profile Q: Is Yuri-Amy an unstable pair? A: No. Yuri prefer Brenda to Amy 4
Last Lecture (summary) Stable matching problem: Given n men and n women, and their preferences, find a stable matching. For a perfect matching M , a pair m-w is unstable if they prefer each other to their match in M. least favorite favorite least favorite favorite 1 st 2 nd 3 rd 1 st 2 nd 3 rd Xavier Amy Brenda Claire Amy Yuri Xavier Zoran Yuri Brenda Amy Claire Brenda Xavier Yuri Zoran Zoran Amy Brenda Claire Claire Xavier Yuri Zoran Men’s Preference Profile Women’s Preference Profile Q: Is Xavier-Amy an unstable pair? A: Yes. 5
Propose-And-Reject Algorithm [Gale-Shapley’62] Initialize each person to be free. while (some man is free and hasn't proposed to every woman) { Choose such a man m w = 1 st woman on m 's list to whom m has not yet proposed if ( w is free) assign m and w to be engaged else if ( w prefers m to her fiancé m' ) assign m and w to be engaged, and m' to be free else w rejects m } 6
Questions • Q: Why GS algorithm solves Stable Matching problem? • Q: How to implement GS algorithm efficiently? • Q: If there are multiple stable matchings, which one does GS find? 7
What do we need to prove? Goal: prove Propose-And-Reject Algorithm always finds a stable matching. • The algorithm ends. How many iterations it takes? • The output is correct. It find a perfect matching that is stable. 8
Main Properties of the algorithm Observation 1: Men propose to women in decreasing order of preference. Observation 2: Once a woman is matched, she never becomes unmatched; she only "trades up." Initialize each person to be free. while (some man is free and hasn't proposed to every woman) { Choose such a man m w = 1 st woman on m 's list to whom m has not yet proposed if ( w is free) assign m and w to be engaged else if ( w prefers m to her fiancé m' ) assign m and w to be engaged, and m' to be free else w rejects m } 9
Proof of Correctness: Termination One strategy to bound # Each step, a man proposed to a new woman. iterations is to find a measure of progress. There are !×! = ! $ possible man-to-woman proposals. Therefore, it takes at most ! $ iterations. 1 st 2 nd 3 rd 4 th 5 th 1 st 2 nd 3 rd 4 th 5 th Victor A B C D E Amy W X Y Z V Walter B C D A E Brenda X Y Z V W Xavier C D A B E Claire Y Z V W X Yuri D A B C E Diane Z V W X Y Zoran A B C D E Erika V W X Y Z n(n-1) + 1 proposals required 10
Proof of Correctness: Perfection Claim. All men and women get matched. Proof. (by contradiction) Suppose, for sake of contradiction, that Zoran is not matched upon termination of algorithm. Then some woman, say Amy, is not matched upon termination. (Observation 2: once women matched, they never becoming unmatched.) Amy was never proposed to. But, Zoran proposes to everyone, since he ends up unmatched. 11
Proof of Correctness: Stability Claim. No unstable pairs. Proof. (by contradiction) Suppose A - Z is an unstable pair: each prefers each other to the partner in Gale-Shapley matching. men propose in decreasing Case 1: Z never proposed to A . order of preference Þ Z prefers his GS partner to A . Þ A - Z is stable. Case 2: Z proposed to A . Þ A rejected Z (right away or later) Þ A prefers her GS partner to Z . women only trade up Þ A - Z is stable. In either case A - Z is stable, a contradiction. 12
Questions • Q: Why GS algorithm solves Stable Matching problem? • Q: How to implement GS algorithm efficiently? • Q: If there are multiple stable matchings, which one does GS find? 13
Propose-And-Reject Algorithm [Gale-Shapley’62] • Input: For each man (woman), a list of women (men) ordered by preference, denoted as pref[m/w, i] O ( n 2 ) Initialize each person to be free. time while (some man is free and hasn't proposed to every woman) { Choose such a man m O ( n ) w = 1 st woman on m 's list to whom m has not yet proposed time if ( w is free) assign m and w to be engaged O ( n ) else if ( w prefers m to her fiancé m' ) time assign m and w to be engaged, and m' to be free else w rejects m } • Maintain two arrays wife [ m ] , and husband [ w ] . • set entry to 0 if unmatched Overall: O ( n 4 ) • if m matched to w then wife [ m ]= w and husband [ w ]= m time • Maintain a matrix proposed[m, w]. 14 • Set entry to 1 if m has proposed to w , otherwise set to 0
Recommend
More recommend