Download presentation
Presentation is loading. Please wait.
Published byΟλυμπιάς Βονόρτας Modified over 6 years ago
1
S. Raskhodnikova; based on slides by K. Wayne
Discrete Math for CS LECTURE 10 Last time: Stable Matching Propose-and-Reject algorithm Today: Analysis of Propose-and-Reject CMPSC 360 11/29/2018 S. Raskhodnikova; based on slides by K. Wayne
2
An Algorithm for Stable Matching
Propose-and-reject algorithm. [Gale-Shapley 1962] Input: tables of preferences for men and women while (there are rejected suitors) { Start a new day. Morning: Every man proposes to 1st women remaining on his list. Afternoon: Every woman says ``Maybe’’ to the man she likes best among the proposals (she now has him on a string) and rejects the rest. Evening: Each rejected suitor crosses off the woman that rejected him from his list. } Last day: Each woman marries the man she has on the string. Output: The set of married couples. 11/29/2018 S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne
3
Example: Execution of the Algorithm
Men’s preferences Women’s preferences Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare stable matching is unique for worst-case instance 11/29/2018
4
Day 1: Morning Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Victor proposes to Bertha. Wyatt proposes to Diane. Xavier proposes to Bertha. Yancey proposes to Amy. Zeus proposes to Bertha. stable matching is unique for worst-case instance 11/29/2018
5
Day 1: Afternoon Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Amy says ``Maybe’’ to Yancey. Bertha says ``Maybe’’ to Xavier, rejects Victor and Zeus. Diane says ``Maybe’’ to Wyatt. stable matching is unique for worst-case instance 11/29/2018
6
Day 1: Evening Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Victor and Zeus cross off Bertha. stable matching is unique for worst-case instance 11/29/2018
7
Day 2: Morning Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Victor proposes to Amy. Wyatt proposes to Diane. Xavier proposes to Bertha. Yancey proposes to Amy. Zeus proposes to Diane. stable matching is unique for worst-case instance 11/29/2018
8
Day 2: Afternoon Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Amy says ``Maybe’’ to Victor, rejects Yancey. Bertha says ``Maybe’’ to Xavier. Diane says ``Maybe’’ to Zeus, rejects Wyatt. stable matching is unique for worst-case instance 11/29/2018
9
Day 2: Evening Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Wyatt crosses off Diane. Yancey crosses off Amy. stable matching is unique for worst-case instance 11/29/2018
10
Day 3: Morning Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Victor proposes to Amy. Wyatt proposes to Bertha. Xavier proposes to Bertha. Yancey proposes to Diane. Zeus proposes to Diane. stable matching is unique for worst-case instance 11/29/2018
11
Day 3: Afternoon Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Amy says ``Maybe’’ to Victor.. Bertha says ``Maybe’’ to Xavier, rejects Wyatt. Diane says ``Maybe’’ to Zeus, rejects Yancey. stable matching is unique for worst-case instance 11/29/2018
12
Day 3: Evening Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Wyatt crosses off Bertha. Yancey crosses off Diane. stable matching is unique for worst-case instance 11/29/2018
13
Day 4: Morning Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Victor proposes to Amy. Wyatt proposes to Amy. Xavier proposes to Bertha. Yancey proposes to Clare. Zeus proposes to Diane. stable matching is unique for worst-case instance 11/29/2018
14
Day 4: Afternoon Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Amy says ``Maybe’’ to Victor., rejects Wyatt. Bertha says ``Maybe’’ to Xavier. Clare says ``Maybe’’ to Yancey. Diane says ``Maybe’’ to Zeus. stable matching is unique for worst-case instance 11/29/2018
15
Day 4: Evening Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Wyatt crosses off Amy. stable matching is unique for worst-case instance 11/29/2018
16
Day 5: Morning Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Victor proposes to Amy. Wyatt proposes to Clare. Xavier proposes to Bertha. Yancey proposes to Clare. Zeus proposes to Diane. stable matching is unique for worst-case instance 11/29/2018
17
Day 5: Afternoon Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Amy says ``Maybe’’ to Victor. Bertha says ``Maybe’’ to Xavier. Clare says ``Maybe’’ to Wyatt, rejects Yancey. Diane says ``Maybe’’ to Zeus. stable matching is unique for worst-case instance 11/29/2018
18
Day 5: Evening Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Yancey crosses off Clare. stable matching is unique for worst-case instance 11/29/2018
19
Day 6: Morning Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Victor proposes to Amy. Wyatt proposes to Clare. Xavier proposes to Bertha. Yancey proposes to Bertha. Zeus proposes to Diane. stable matching is unique for worst-case instance 11/29/2018
20
Day 6: Afternoon Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Amy says ``Maybe’’ to Victor. Bertha says ``Maybe’’ to Xavier, rejects Yancey. Clare says ``Maybe’’ to Wyatt. Diane says ``Maybe’’ to Zeus. stable matching is unique for worst-case instance 11/29/2018
21
Day 6: Evening Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Yancey crosses off Bertha. stable matching is unique for worst-case instance 11/29/2018
22
Day 7: Morning Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Victor proposes to Amy. Wyatt proposes to Clare. Xavier proposes to Bertha. Yancey proposes to Erika. Zeus proposes to Diane. stable matching is unique for worst-case instance 11/29/2018
23
Day 7: Afternoon Men’s preferences Women’s preferences
Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Amy says ``Maybe’’ to Victor. Bertha says ``Maybe’’ to Xavier. Clare says ``Maybe’’ to Wyatt. Diane says ``Maybe’’ to Zeus. Erika says ``Maybe’’ to Yancey. stable matching is unique for worst-case instance 11/29/2018
24
Day 7: Evening (Happy End)
Men’s preferences Women’s preferences Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare Output of our algorithm. The following couples get married: Victor and Amy, Wyatt and Clare, Xavier and Bertha, Yancey and Erika, Zeus and Diane. stable matching is unique for worst-case instance 11/29/2018
25
I-clicker question (frequency: BC)
True or false? In the propose-and-reject algorithm, each day some man proposes to a new woman. True. False. 11/29/2018
26
I-clicker question (frequency: BC)
True or false? In the propose-and-reject algorithm, each day some man proposes to a new woman. True. False. Answer: True. If proposals are the same on two consecutive days, it means that nobody got rejected the day before. 11/29/2018
27
Proof of Correctness: Termination
Lemma. Algorithm runs for at most 𝒏 𝟐 days. Proof. Each day some man proposes to a new woman. There are 𝒏 men, 𝒏 women. Overall, 𝒏 𝟐 possible proposals. ▪ Wyatt Victor 1st A B 2nd C D 3rd Zeus Yancey Xavier 4th E 5th Bertha Amy W X Y Z V Erika Diane Clare stable matching is unique for worst-case instance An instance where n(n-2) + 2 days are required 11/29/2018
28
Analysis of Propose-and-Reject Algorithm
Observation. Men propose to women in decreasing order of preference. Improvement lemma (``women trade up’’). Once a woman gets a proposal from a man 𝑚, starting from that day, she has somebody on a string that she likes at least as much as 𝑚. Men’s preferences Women’s preferences Wyatt Victor 1st B D 2nd A 3rd Zeus Yancey Xavier C E 4th 5th Bertha Amy Z X W Y V Erika Diane Clare stable matching is unique for worst-case instance 11/29/2018
29
Proof of Correctness: Perfection
Lemma. All men and women get matched. Proof: (by contradiction) Suppose, for the sake of contradiction, some guy, say Zeus, is not matched upon termination of the algorithm. Then some woman, say Amy, is not matched upon termination. By Improvement Lemma, Amy was never proposed to. But Zeus proposes to everyone, since he ends up unmatched. Contradiction. ▪ 11/29/2018
30
Proof of Correctness: Stability
Claim. The final matching has no rogue pairs. Proof: (by contradiction) Suppose A-Z is a rogue pair: they prefer each other to their partners in Gale-Shapley matching S*. Case 1: Z never proposed to A. Z prefers his GS partner to A. A-Z is not rogue. Case 2: Z proposed to A. A rejected Z (right away or later) A prefers her GS partner to Z. A-Z is not rogue. In either case A-Z is not rogue, a contradiction. ▪ men propose in decreasing order of preference women only trade up 11/29/2018
31
Summary Stable matching problem. Given n men and n women, and their preferences, find a stable matching if one exists. Gale-Shapley algorithm. Guarantees to find a stable matching for every problem instance. (Also proves that a stable matching always exists.) Time: It can be implemented to run efficiently. 11/29/2018
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.