Discrete Math for CS LECTURE 10 Last time

![An Algorithm for Stable Matching • Propose-and-reject algorithm. [Gale-Shapley 1962] Input: tables of preferences An Algorithm for Stable Matching • Propose-and-reject algorithm. [Gale-Shapley 1962] Input: tables of preferences](https://slidetodoc.com/presentation_image_h2/75b5ea1fcba82c93b809e7f1d7cb0aaf/image-2.jpg)





























- Slides: 31
Discrete Math for CS LECTURE 10 Last time: • Stable Matching • Propose-and-Reject algorithm Today: • Analysis of Propose-and-Reject 6/16/2021 S. Raskhodnikova; based on slides by K. Wayne
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 1 st 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. 6/16/2021 S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne
Example: Execution of the Algorithm Men’s preferences 6/16/2021 Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V
Day 1: Morning Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Victor proposes to Bertha. Wyatt proposes to Diane. Xavier proposes to Bertha. Yancey proposes to Amy. Zeus proposes to Bertha. 6/16/2021
Day 1: Afternoon Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Amy says ``Maybe’’ to Yancey. Bertha says ``Maybe’’ to Xavier, rejects Victor and Zeus. Diane says ``Maybe’’ to Wyatt. 6/16/2021
Day 1: Evening Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Victor and Zeus cross off Bertha. 6/16/2021
Day 2: Morning Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Victor proposes to Amy. Wyatt proposes to Diane. Xavier proposes to Bertha. Yancey proposes to Amy. Zeus proposes to Diane. 6/16/2021
Day 2: Afternoon Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Amy says ``Maybe’’ to Victor, rejects Yancey. Bertha says ``Maybe’’ to Xavier. Diane says ``Maybe’’ to Zeus, rejects Wyatt. 6/16/2021
Day 2: Evening Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Wyatt crosses off Diane. Yancey crosses off Amy. 6/16/2021
Day 3: Morning Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Victor proposes to Amy. Wyatt proposes to Bertha. Xavier proposes to Bertha. Yancey proposes to Diane. Zeus proposes to Diane. 6/16/2021
Day 3: Afternoon Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Amy says ``Maybe’’ to Victor. . Bertha says ``Maybe’’ to Xavier, rejects Wyatt. Diane says ``Maybe’’ to Zeus, rejects Yancey. 6/16/2021
Day 3: Evening Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Wyatt crosses off Bertha. Yancey crosses off Diane. 6/16/2021
Day 4: Morning Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Victor proposes to Amy. Wyatt proposes to Amy. Xavier proposes to Bertha. Yancey proposes to Clare. Zeus proposes to Diane. 6/16/2021
Day 4: Afternoon Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Amy says ``Maybe’’ to Victor. , rejects Wyatt. Bertha says ``Maybe’’ to Xavier. Clare says ``Maybe’’ to Yancey. Diane says ``Maybe’’ to Zeus. 6/16/2021
Day 4: Evening Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Wyatt crosses off Amy. 6/16/2021
Day 5: Morning Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Victor proposes to Amy. Wyatt proposes to Clare. Xavier proposes to Bertha. Yancey proposes to Clare. Zeus proposes to Diane. 6/16/2021
Day 5: Afternoon Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Amy says ``Maybe’’ to Victor. Bertha says ``Maybe’’ to Xavier. Clare says ``Maybe’’ to Wyatt, rejects Yancey. Diane says ``Maybe’’ to Zeus. 6/16/2021
Day 5: Evening Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Yancey crosses off Clare. 6/16/2021
Day 6: Morning Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Victor proposes to Amy. Wyatt proposes to Clare. Xavier proposes to Bertha. Yancey proposes to Bertha. Zeus proposes to Diane. 6/16/2021
Day 6: Afternoon Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Amy says ``Maybe’’ to Victor. Bertha says ``Maybe’’ to Xavier, rejects Yancey. Clare says ``Maybe’’ to Wyatt. Diane says ``Maybe’’ to Zeus. 6/16/2021
Day 6: Evening Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Yancey crosses off Bertha. 6/16/2021
Day 7: Morning Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Victor proposes to Amy. Wyatt proposes to Clare. Xavier proposes to Bertha. Yancey proposes to Erika. Zeus proposes to Diane. 6/16/2021
Day 7: Afternoon Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V 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. 6/16/2021
Day 7: Evening (Happy End) Men’s preferences Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V Output of our algorithm. The following couples get married: Victor and Amy, Wyatt and Clare, Xavier and Bertha, Yancey and Erika, Zeus and Diane. 6/16/2021
I-clicker question (frequency: BC) True or false? In the propose-and-reject algorithm, each day some man proposes to a new woman. A. True. B. False. 6/16/2021
I-clicker question (frequency: BC) True or false? In the propose-and-reject algorithm, each day some man proposes to a new woman. A. True. B. False. Answer: True. If proposals are the same on two consecutive days, it means that nobody got rejected the day before. 6/16/2021
Proof of Correctness: Termination • 1 st 2 nd 3 rd 4 th 5 th Victor A B C D E Amy W X Y Z V Wyatt B C D A E Bertha X Y Z V W Xavier C D A B E Clare Y Z V W X Yancey D A B C E Diane Z V W X Y Zeus A B C D E Erika V W X Y Z An instance where n(n-2) + 2 days are required 6/16/2021
Analysis of Propose-and-Reject Algorithm • Men’s preferences 6/16/2021 Women’s preferences 1 st 2 nd 3 rd 4 th 5 th Victor B A D E C Amy Z V W Y X Wyatt D B A C E Bertha X W Y V Z Xavier B E C D A Clare W X Y Z V Yancey A D C B E Diane V Z Y X W Zeus B D A E C Erika Y W Z X V
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. ▪ 6/16/2021
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. men propose in decreasing Z prefers his GS partner to A. A-Z is not rogue. order of preference – 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. women only trade up – In either case A-Z is not rogue, a contradiction. ▪ 6/16/2021
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. 6/16/2021