Stable marriages Competitive programming and problem solving Yoram Meijaard.

Slides:



Advertisements
Similar presentations
Of.
Advertisements

High Frequency Words List A Group 1
Piyush Kumar (Lecture 3: Stable Marriage) Welcome to COT5405.
Great Theoretical Ideas in Computer Science
1 Overview of Graph Theory Addendum “The Stable Marriage Problem” Instructor: Carlos Pomalaza-Ráez Fall 2003 University of Oulu, Finland.
Tutorial 5 of CSCI2110 Eulerian Path & Hamiltonian Cycle Tutor: Zhou Hong ( 周宏 )
Great Theoretical Ideas in Computer Science for Some.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Matching problems Toby Walsh NICTA and UNSW. Motivation Agents may express preferences for issues other than a collective decision  Preferences for a.
Social Networks 101 P ROF. J ASON H ARTLINE AND P ROF. N ICOLE I MMORLICA.
1 Discrete Structures & Algorithms Graphs and Trees: IV EECE 320.
Stable Marriage Problem William Kozma Jr ECE 443/543.
Lecture 4 CSE 331 Sep 9, Blog posts for lectures Starts from today See Sep 8 post on the blog.
Lecture 7 CSE 331 Sep 16, Feedback forms VOLUNTARY Last 5 mins of the lecture.
Lecture 8 CSE 331 Sep 18, Homeworks Hand in your HW 1 HW 2 and solutions to HW 1 out at the end of class Not naming your collaborators is same as.
Lecture 8 CSE 331 Sep 17, HW 1 due today Place Q1 and Q2 in separate piles I will not accept HWs after 1:15pm.
1st 100 sight words.
CEG 221 Lesson 7: Algorithm Development From Start to Finish Mr. David Lippa.
Week 11 - Friday.  What did we talk about last time?  Exam 2 post mortem  Cycle detection  Connectivity.
Lecture 6 CSE 331 Sep 10, Homeworks HW 1 posted online: see blog/piazza Pickup graded HW 0 in TA OHs.
Chapter 10: Iterative Improvement Simplex Method The Design and Analysis of Algorithms.
The Stable Marriage Problem
1 Stable Matching Problem Goal. Given n men and n women, find a "suitable" matching. n Participants rate members of opposite sex. n Each man lists women.
List A Sight Words.
The Mathematics Of 1950’s Dating: Who wins the battle of the sexes? Adapted from a presentation by Stephen Rudich.
The Mathematics Of 1950’s Dating: Who wins the battle of the sexes? Presentation by Shuchi Chawla with some modifications.
Lecture 3 CSE 331. Stable Matching Problem Problem Statement Algorithm Problem Definition Implementation Analysis.
Lecture 2 CSE 331. Day 1 Survey On UBlearns Day 1 Survey (talking points) Security MS PhD for research Building PC’s for 442 It’s ok to play games –
Stable Matchings a.k.a. the Stable Marriage Problem
Lecture 5 CSE 331 Sep 11, Submit the form I’ll need confirmation in writing. No graded material will be handed back till I get this signed form.
CSE 331: Review. Main Steps in Algorithm Design Problem Statement Algorithm Real world problem Problem Definition Precise mathematical def “Implementation”
Great Theoretical Ideas in Computer Science.
1 The Stable Marriage Problem Algorithms and Networks 2014/2015 Hans L. Bodlaender Johan M. M. van Rooij.
Marriage and Mathematics Lau Ting Sum Samson Suen Wai.
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
Stable Matching Lecture 7: Oct 3. Matching A B C DE Boys Girls Today’s goal: to “match” the boys and the girls in a “good” way.
Stable Marriages (Lecture modified from Carnegie Mellon University course Great Theoretical Ideas in Computer Science)
Design & Co-design of Embedded Systems Final Project: “The Match Maker” Second Phase Oral Presentation Safa S. Mahmoodian.
The Stable Marriage Problem
Great Theoretical Ideas in Computer Science for Some.
Matching Lecture 19: Nov 23.
Sep 29, 2014 Lirong Xia Matching. Report your preferences over papers soon! –deadline this Thursday before the class Drop deadline Oct 17 Catalan independence.
CSCI 256 Data Structures and Algorithm Analysis Lecture 2 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
Market Design and Analysis Lecture 2 Lecturer: Ning Chen ( 陈宁 )
18.1 CompSci 102 Today’s topics 1950s TV Dating1950s TV Dating.
Algorithms used by CDNs Stable Marriage Algorithm Consistent Hashing.
CompSci Today’s Topics Computer Science Noncomputability Upcoming Special Topic: Enabled by Computer -- Decoding the Human Genome Reading Great.
Matching Boys Girls A B C D E
Cybernetica AS & Tartu University
Stable Matching.
Lecture 4 CSE 331 Sep 7, 2016.
The Stable Marriage Problem
Apollo Weize Sun, Mar.10th, 2017.
Lecture 8 CSE 331 Sep 14, 2011.
CSE 421: Introduction to Algorithms
Lecture 5 CSE 331 Sep 10, 2010.
Lecture 4 CSE 331 Sep 6, 2017.
Lecture 6 CSE 331 Sep 11, 2017.
Richard Anderson Autumn 2006 Lecture 1
CSE 421: Introduction to Algorithms
Lecture 5 CSE 331 Sep 6, 2013.
Lecture 6 CSE 331 Sep 12, 2011.
Lecture 9 CSE 331 Sep 20, 2010.
Lecture 5 CSE 331 Sep 5, 2014.
Lecture 6 CSE 331 Sep 12, 2016.
Richard Anderson Winter 2009 Lecture 2
Piyush Kumar (Lecture 3: Stable Marriage)
Sum this up for me Let’s write a method to calculate the sum from 1 to some n public static int sum1(int n) { int sum = 0; for (int i = 1; i
Lecture 7 CSE 331 Sep 11, 2013.
Looping Structures.
Presentation transcript:

Stable marriages Competitive programming and problem solving Yoram Meijaard

Today The stable marriage problem  Problem statement  Solution  Proof  Running time  Reenactment  Implementation  Adaptations  Applications  Practice

Problem statement Imagine we have a village With people

Problem statement 100 boys 100 girls

Problem statement We are a matchmaker We would like to arrange 100 marriages Is this possible? Are they stable?

Solution - Classic Human inefficiency Solution? Computer science!

Problem statement (finally)

Solution 1.Every boy ranks the girls in a strict order of preference 2.Every girl ranks the boys in a strict order of preference 3.Repeat, until everyone is engaged: a)Every unengaged boy proposes to highest ranked girl that he hasn't proposed to on his list b)All girls accept the highest ranked boy who has proposed to her All marriages are stable All people are married

Example ABC XZZ YYX ZXY XYZ BCB CAC ABA RoundProposalsXYZ 1A-X, B-Z,C-ZAB 2C-XCB 3A-YCAB A proposes to X B proposes to Z C proposes to Z X accepts A Z accepts B C proposes to X X accepts C (A now single) A proposes to Y Y accepts A

Algorithm 1.Every boy ranks the girls in a strict order of preference 2.Every girl ranks the boys in a strict order of preference 3.Repeat, until everyone is engaged: a)Every unengaged boy proposes to highest ranked girl that he hasn't proposed to on his list b)All girls accept the highest ranked boy who has proposed to her

Proof – Part 1: does everyone get married? Property : #engaged boys = #engaged girls Property : if a girl is proposed to, she will be engaged for the rest of the algorithm. Proof by contradiction: Assume the loop ends Assume that there exist a boy A and girl B that are not engaged Then no one has proposed to B Thus A has not proposed to B Thus the loop cannot have ended.

Proof – Part 2: every marriage is stable

Algorithm 1.Every boy ranks the girls in a strict order of preference 2.Every girl ranks the boys in a strict order of preference 3.Repeat, until everyone is engaged: a)Every unengaged boy proposes to highest ranked girl that he hasn't proposed to on his list b)All girls accept the highest ranked boy who has proposed to her

Runtime Runtime equivalent to the amount of proposals made How many proposals are possible? All boys x all girls = n^2 Every round the supply of proposals drops by at least one Runtime= O(n^2)

Reenactment

Algorithm 1.Every boy ranks the girls in a strict order of preference 2.Every girl ranks the boys in a strict order of preference 3.Repeat, until everyone is engaged: a)Every unengaged boy proposes to highest ranked girl that he hasn't proposed to on his list b)All girls accept the highest ranked boy who has proposed to her

Implementation Input: Idea: represent all boys and girls as index int[] boy_engagedTo = new int[n]; // status of boys, filled with -1’s int[] girl_engagedTo = new int[n]; // status of girls, filled with -1’s int[] proposals_made = new int[n]; // amount of proposals made int[][] boy_pref = new int[n][n]; // filled with preferences of boys int[][] girl_pref = new int[n][n]; // filled with preferences of girls Queue q = new LinkedList<>();// available boys for(int I = 0; i < n; i++){// add all boys to queue q.add(i); } Output: for(int i = 0; i < n;i++){// output all boys and their matches System.out.println((i+1) + " " + (boy_engagedTo[i] + 1)); }

Implementation while(!q.isEmpty()){ int boy = q.poll();// get an unengaged guy int girl = boy_pref[boy][proposals_made[boy]++];// girl he wants to propose to if(girl_engagedTo[girl] == -1){// she is unengaged girl_engagedTo[girl] = boy; boy_engagedTo[boy] = girl; } else {// she is engaged for(int i=0;i<n;i++){// find out if boy is more preferred int b = girl_pref[girl][i]; if(b==boy){ boy_engagedTo[girl] =-1; //unengage the guy q.add(girl_engagedTo[girl]); // add him to the list of sad losers girl_engagedTo[girl] = boy; boy_engagedTo[boy] = girl; break; } else if(b==girl_engagedTo[girl]) { q.add(boy); break; }}}}

Adaptations College admission problem Matches x Colleges with q x spots to n Students Extreme case: x = n  stable marriage problem! In general: take students as Boys, take colleges spots as Girls Run stable marriage

Applications Server routing E-matching? Economics  game theory

Practice && Misc Numberphile on stable marriages My “prerecording”, in case you want me to explain it again

Questions?