Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2013.

Slides:



Advertisements
Similar presentations
Piyush Kumar (Lecture 3: Stable Marriage) Welcome to COT5405.
Advertisements

Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2013 Lecture 2.
Matching Theory.
Matching problems Toby Walsh NICTA and UNSW. Motivation Agents may express preferences for issues other than a collective decision  Preferences for a.
CSC 430 Lecture1: Introduction and Python Primer.
Telling a computer how to behave (via pseudocode -- a workaround for Computing’s Tower of Babel.) COS 116, Spring 2010 Adam Finkelstein.
CSE 421 Algorithms Richard Anderson Lecture 2. Announcements Office Hours –Richard Anderson, CSE 582 Monday, 10:00 – 11:00 Friday, 11:00 – 12:00 –Yiannis.
Chapter 26 of CLSR Bipartite Matching By Dr. M. Sakalli, Sources: Levitin and many other CSE, Marmara Univ. May/2009.
Lecture 4 CSE 331 Sep 9, Blog posts for lectures Starts from today See Sep 8 post on the blog.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne COS 423: Theory of Algorithms Princeton University Spring, 2001 Kevin Wayne.
A Longer Example: Stable Matching UNC Chapel HillZ. Guo.
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.
9/3/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Guest lecturer: Martin Furer Algorithm Design and Analysis L ECTURE.
Telling a computer how to behave (via pseudocode -- a workaround for Computing’s Tower of Babel.) COS 116, Spring 2012 Adam Finkelstein.
Creating new worlds inside the computer COS 116: 2/10/2011 Sanjeev Arora.
Piyush Kumar (Lecture 1: Introduction) Welcome to COT5405.
Piyush Kumar (Lecture 1: Introduction)
CSC 430 Lecture1: Introduction and Python Primer.
The Stable Marriage Problem
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 1.
1 Chapter 1 Introduction: Some Representative Problems Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
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.
L3 #1 The Hospitals / Residents Problem and Some Extensions David Manlove University of Glasgow Department of Computing Science Supported by EPSRC grant.
Lecture 3 CSE 331. Stable Matching Problem Problem Statement Algorithm Problem Definition Implementation Analysis.
Advanced Algorithms Piyush Kumar (Lecture 1: Introduction) Welcome to COT5405.
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
CSE 331: Review. Main Steps in Algorithm Design Problem Statement Algorithm Real world problem Problem Definition Precise mathematical def “Implementation”
1 The Stable Marriage Problem Algorithms and Networks 2014/2015 Hans L. Bodlaender Johan M. M. van Rooij.
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.
1 Chapter 1 Introduction: Some Representative Problems Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 1.
Complexity & Analysis of Data Structures & Algorithms Piyush Kumar (Lecture 1: Introduction) Welcome to COP4531 Based on slides from J. Edmonds, S. Rudich,
CSE 421 Algorithms Richard Anderson (for Anna Karlin) Winter 2006 Lecture 2.
The Stable Marriage Problem
Matching Lecture 19: Nov 23.
1 Chapter 5-1 Greedy Algorithms Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
CSCI 256 Data Structures and Algorithm Analysis lecture 1 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
Graph Algorithms Maximum Flow - Best algorithms [Adapted from R.Solis-Oba]
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 ( 陈宁 )
Market Design and Analysis Lecture 1 Lecturer: Ning Chen ( 陈宁 )
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 3.
COMP9007: Algorithms Stable Matching. What's in an algorithm? Algorithms can have huge impact For example – A report to the White House from 2010 includes.
Matching Boys Girls A B C D E
Cybernetica AS & Tartu University
Stable Matching.
Chapter 1 Introduction: Some Representative Problems
Chapter 10 Iterative Improvement
The Stable Marriage Problem
Piyush Kumar (Lecture 1: Introduction)
Piyush Kumar (Lecture 1: Introduction)
CSE 421: Introduction to Algorithms
Complexity & Analysis of Data Structures & Algorithms
Richard Anderson (for Anna Karlin) Winter 2006 Lecture 1
S. Raskhodnikova; based on slides by K. Wayne
Richard Anderson Autumn 2006 Lecture 1
CSE 421: Introduction to Algorithms
1.1 A First Problem: Stable Matching
Discrete Math for CS CMPSC 360 LECTURE 9 Last time: Strong induction
Richard Anderson Autumn 2015 Lecture 1
Chapter 1 Introduction: Some Representative Problems
Piyush Kumar (Lecture 1: Introduction)
Lecture 6 CSE 331 Sep 12, 2011.
Lecture 7 CSE 331 Sep 10, 2014.
Richard Anderson Winter 2019 Lecture 1
Piyush Kumar (Lecture 3: Stable Marriage)
Lecture 7 CSE 331 Sep 11, 2013.
Piyush Kumar (Lecture 1: Introduction)
Richard Anderson Winter 2019 Lecture 2
Presentation transcript:

Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2013

Design 2 Analysis Algorithms

What you will learn in this course How to abstract messy, real-world problems by clean algorithmic problems How to solve those algorithmic problems (design) Examine problem structure Pick and choose from different algorithm design strategies How to mathematically analyze algorithms (analysis) Why? Because we want guarantees Quantify different design choices Proof techniques are as important as results 3

… and how By reading the (required) textbook “Algorithm Design,” Kleinberg and Tardos, Addison- Wesley. Attending lectures, doing assigned readings Slides will be made available before the class Solving lots of practice problems In-class problem solving Assignments In-class exams Quizzes 4

Administrative matters My TAs: TBD Course website: Contains information about office hours, grading policies, etc. Read this information carefully; if you have questions. Lecture slides and assignments will be posted here. Owlspace page Sp Sp13 Questions, discussions, announcements, quizzes Also restricted material such as solutions to exercises. 5

Policies No laptops in class. We won’t take attendance. But Learning in this course will have a strong active component You will have to work in pairs on problems in class Some of this work will be collected and count towards class participation For some lectures, we will assign readings You will be expected to do the reading ahead of time. Policies on homework, grading, collaboration, etc. are available on the course website 6

Some representative problems 1.1 A First Problem: Stable Matching [Adapted from slides by Kevin Wayne.]

8 Matching Residents to Hospitals Goal. Given a set of preferences among hospitals and medical school students, design a self-reinforcing admissions process. Unstable pair: applicant x and hospital y are unstable if: n x prefers y to its assigned hospital. n y prefers x to one of its admitted students. Stable assignment. Assignment with no unstable pairs. n Natural and desirable condition. n Individual self-interest will prevent any applicant/hospital deal from being made.

Asymmetries in the resident-matching problem Each student matched to one hospital, but a hospital admits multiple students # of students may differ from # of available slots Not all students may list every hospital 9 Let us simplify…

10 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 in order of preference from best to worst. n Each woman lists men in order of preference from best to worst. ZeusAmyClareBertha YanceyBerthaClareAmy XavierAmyClareBertha 1 st 2 nd 3 rd Men’s Preference Profile favoriteleast favorite ClareXavierZeusYancey BerthaXavierZeusYancey AmyYanceyZeusXavier 1 st 2 nd 3 rd Women’s Preference Profile favoriteleast favorite

11 Stable Matching Problem Perfect matching: everyone is matched monogamously. n Each man gets exactly one woman. n Each woman gets exactly one man. Stability: no incentive for some pair of participants to undermine assignment by joint action. n In matching M, an unmatched pair m-w is unstable if man m and woman w prefer each other to current partners. n Unstable pair m-w could each improve by eloping. Stable matching: perfect matching with no unstable pairs. Stable matching problem. Given the preference lists of n men and n women, find a stable matching if one exists.

12 Stable Matching Problem Q. Is assignment X-C, Y-B, Z-A stable? ZeusAmyClareBertha YanceyBerthaClareAmy XavierAmyClareBertha 1 st 2 nd 3 rd Men’s Preference Profile ClareXavierZeusYancey BerthaXavierZeusYancey AmyYanceyZeusXavier 1 st 2 nd 3 rd Women’s Preference Profile favoriteleast favoritefavorite least favorite

13 Stable Matching Problem Q. Is assignment X-C, Y-B, Z-A stable? A. No. Bertha and Xavier will get together. ZeusAmyClareBertha YanceyBerthaClareAmy XavierAmyClareBertha ClareXavierZeusYancey BerthaXavierZeusYancey AmyYanceyZeusXavier 1 st 2 nd 3 rd 1 st 2 nd 3 rd favoriteleast favoritefavorite least favorite Men’s Preference ProfileWomen’s Preference Profile

Q1: OK, find a stable matching then … and put it down in your worksheet! 14 ZeusAmyClareBertha YanceyBerthaClareAmy XavierAmyClareBertha 1 st 2 nd 3 rd Men’s Preference Profile ClareXavierZeusYancey BerthaXavierZeusYancey AmyYanceyZeusXavier 1 st 2 nd 3 rd Women’s Preference Profile favoriteleast favoritefavorite least favorite

15 Stable Matching Problem Q. Is assignment X-A, Y-B, Z-C stable? A. Yes. ZeusAmyClareBertha YanceyBerthaClareAmy XavierAmyClareBertha ClareXavierZeusYancey BerthaXavierZeusYancey AmyYanceyZeusXavier 1 st 2 nd 3 rd 1 st 2 nd 3 rd favoriteleast favoritefavorite least favorite Men’s Preference ProfileWomen’s Preference Profile

16 Stable Roommate Problem Q. Do stable matchings always exist? A. Not obvious a priori. Stable roommate problem. n 2n people; each person ranks others from 1 to 2n-1. n Assign roommate pairs so that no unstable pairs. Observation. Stable matchings do not always exist for stable roommate problem. B Bob Chris Adam C A B D D Doofus ABC D C A 1 st 2 nd 3 rd A-B, C-D  B-C unstable A-C, B-D  A-B unstable A-D, B-C  A-C unstable

17 Propose-And-Reject Algorithm Propose-and-reject algorithm. [Gale-Shapley 1962] Intuitive method that guarantees to find a stable matching. 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 }

18 Proof of Correctness: Termination 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." Claim. Algorithm terminates after at most n 2 iterations of while loop. Q2: prove this claim!

19 Proof of Correctness: Termination 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." Claim. Algorithm terminates after at most n 2 iterations of while loop. Pf. Each time through the while loop a man proposes to a new woman. There are only n 2 possible proposals. ▪ Wyatt Victor 1 st A B 2 nd C D 3 rd C B AZeus Yancey XavierC D A B B A D C 4 th E E 5 th A D E E D C B E Bertha Amy 1 st W X 2 nd Y Z 3 rd Y X VErika Diane ClareY Z V W W V Z X 4 th V W 5 th V Z X Y Y X W Z n(n-1) + 1 proposals required

20 Proof of Correctness: Perfection Claim. All men and women get matched. Pf. (by contradiction) n Suppose, for sake of contradiction, that Zeus is not matched upon termination of algorithm. n Then some woman, say Amy, is not matched upon termination. n By Observation 2, Amy was never proposed to. n But, Zeus proposes to everyone, since he ends up unmatched. ▪

21 Q3: Proof of Correctness: Stability Claim. There are no unstable pairs in the matching produced by the Gale-Shapley algorithm. Prove this by contradiction. (For this problem, you can talk to the person next to you.)

22 Proof of Correctness: Stability Claim. No unstable pairs. Pf. (by contradiction) n Suppose A-Z is an unstable pair: each prefers each other to partner in Gale-Shapley matching S*. n Case 1: Z never proposed to A.  Z prefers his GS partner to A.  A-Z is stable. n Case 2: Z proposed to A.  A rejected Z (right away or later)  A prefers her GS partner to Z.  A-Z is stable. n In either case A-Z is stable, a contradiction. ▪ Bertha-Zeus Amy-Yancey S*... men propose in decreasing order of preference women only trade up

23 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 any problem instance. Q. How to implement GS algorithm efficiently? Q. If there are multiple stable matchings, which one does GS find?

24 Efficient Implementation Efficient implementation. We describe O(n 2 ) time implementation. Representing men and women. n Assume men are named 1, …, n. n Assume women are named 1', …, n'. Engagements. n Maintain a list of free men, e.g., in a queue. Maintain two arrays wife[m], and husband[w]. – set entry to 0 if unmatched – if m matched to w then wife[m]=w and husband[w]=m Men proposing. n For each man, maintain a list of women, ordered by preference. Maintain an array count[m] that counts the number of proposals made by man m.

25 Efficient Implementation Women rejecting/accepting. Does woman w prefer man m to man m' ? n For each woman, create inverse of preference list of men. n Constant time access for each query after O(n) preprocessing. for i = 1 to n inverse[pref[i]] = i Pref 1 st 8 2 nd 7 3 rd 3 4 th 4 5 th th 7 th 8 th Inverse4 th 2 nd 8 th 6 th 5 th 7 th 1 st 3 rd Amy Amy prefers man 3 to 6 since inverse[3] < inverse[6] 2 7

26 Understanding the Solution Q. For a given problem instance, there may be several stable matchings. Do all executions of Gale-Shapley yield the same stable matching? If so, which one? An instance with two stable matchings. n A-X, B-Y, C-Z. n A-Y, B-X, C-Z. Zeus Yancey Xavier A B A 1 st B A B 2 nd C C C 3 rd Clare Bertha Amy X X Y 1 st Y Y X 2 nd Z Z Z 3 rd

27 Understanding the Solution Q. For a given problem instance, there may be several stable matchings. Do all executions of Gale-Shapley yield the same stable matching? If so, which one? Def. Man m is a valid partner of woman w if there exists some stable matching in which they are matched. Man-optimal assignment. Each man receives best valid partner. Claim. All executions of GS yield man-optimal assignment, which is a stable matching! n No reason a priori to believe that man-optimal assignment is perfect, let alone stable. n Simultaneously best for each and every man.

28 Man Optimality Claim. GS matching S* is man-optimal. Pf. (by contradiction) n Suppose some man is paired with someone other than best partner. Men propose in decreasing order of preference  some man is rejected by valid partner. n Let Y be first such man, and let A be first valid woman that rejects him. n Let S be a stable matching where A and Y are matched. n When Y is rejected, A forms (or reaffirms) engagement with a man, say Z, whom she prefers to Y. n Let B be Z's partner in S. n Z not rejected by any valid partner at the point when Y is rejected by A. Thus, Z prefers A to B. n But A prefers Z to Y. n Thus A-Z is unstable in S. ▪ Bertha-Zeus Amy-Yancey S... since this is first rejection by a valid partner

29 Stable Matching Summary Stable matching problem. Given preference profiles of n men and n women, find a stable matching. Gale-Shapley algorithm. Finds a stable matching in O(n 2 ) time. Man-optimality. In version of GS where men propose, each man receives best valid partner. Q. Does man-optimality come at the expense of the women? no man and woman prefer to be with each other than assigned partner w is a valid partner of m if there exist some stable matching where m and w are paired

30 Q4: Woman Pessimality Woman-pessimal assignment. Each woman receives worst valid partner. Claim. GS finds woman-pessimal stable matching S*. Prove this using contradiction. Use the man-optimality property of the algorithm.

31 Woman Pessimality Woman-pessimal assignment. Each woman receives worst valid partner. Claim. GS finds woman-pessimal stable matching S*. Pf. n Suppose A-Z matched in S*, but Z is not worst valid partner for A. n There exists stable matching S in which A is paired with a man, say Y, whom she likes less than Z. n Let B be Z's partner in S. n Z prefers A to B. n Thus, A-Z is an unstable in S. ▪ Bertha-Zeus Amy-Yancey S... man-optimality

32 Extensions: Matching Residents to Hospitals Ex: Men  hospitals, Women  med school residents. Variant 1. Some participants declare others as unacceptable. Variant 2. Unequal number of men and women. Variant 3. Limited polygamy. Def. Matching S unstable if there is a hospital h and resident r such that: n h and r are acceptable to each other; and n either r is unmatched, or r prefers h to her assigned hospital; and n either h does not have all its places filled, or h prefers r to at least one of its assigned residents. resident A unwilling to work in College Station hospital X wants to hire 3 residents

33 Application: Matching Residents to Hospitals NRMP. (National Resident Matching Program) n Original use just after WWII. n 23,000+ residents. Rural hospital dilemma. n Certain hospitals (mainly in rural areas) were unpopular and declared unacceptable by many residents. n Rural hospitals were under-subscribed in NRMP matching. n How can we find stable matching that benefits "rural hospitals"? Rural Hospital Theorem. Rural hospitals get exactly same residents in every stable matching! predates computer usage

34 Lessons Learned Powerful ideas learned in course. n Isolate underlying structure of problem. n Create useful and efficient algorithms. Potentially deep social ramifications. [legal disclaimer]

1.2 Five Representative Problems

36 Interval Scheduling Input. Set of jobs with start times and finish times. Goal. Find maximum cardinality subset of mutually compatible jobs. Time f g h e a b c d h e b jobs don't overlap

37 Weighted Interval Scheduling Input. Set of jobs with start times, finish times, and weights. Goal. Find maximum weight subset of mutually compatible jobs. Time

38 Bipartite Matching Input. Bipartite graph. Goal. Find maximum cardinality matching. C A E 3 B D4

39 Independent Set Input. Graph. Goal. Find maximum cardinality independent set subset of nodes such that no two joined by an edge

40 Competitive Facility Location Input. Graph with weight on each node. Game. Two competing players alternate in selecting nodes. Not allowed to select a node if any of its neighbors have been selected. Goal. Strategy for Player 2 to select a subset of nodes of weight > B Second player can guarantee 20, but not 25.

41 Five Representative Problems Variations on a theme: independent set. Interval scheduling: n log n greedy algorithm. Weighted interval scheduling: n log n dynamic programming algorithm. Bipartite matching: n k max-flow based algorithm. Independent set: NP-complete. Competitive facility location: PSPACE-complete.