Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 256 Data Structures and Algorithm Analysis Lecture 2 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Similar presentations


Presentation on theme: "CSCI 256 Data Structures and Algorithm Analysis Lecture 2 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some."— Presentation transcript:

1 CSCI 256 Data Structures and Algorithm Analysis Lecture 2 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some by Iker Gondra

2 Stable Matching Problem (Recall) Perfect matching Preference lists (ranking is strictly increasing) Stability –Following is not stable m1m1 w1w1 m2m2 w2w2

3 Propose-And-Reject Algorithm (Recall) Propose-and-reject algorithm [Gale-Shapley 1962]: Intuitive method that guarantees output which is 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 }

4 Does this Work? Does it terminate? Is the result a stable matching? Is there a unique solution? What is the complexity Begin analysis by identifying measures of progress and invariants –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.”

5 Proof of Correctness: Termination Denote a Gale-Shapely marching by S* Claim: Algorithm terminates after at most n 2 iterations of while loop. Why? –Pf: Each time through the while loop a man proposes to a new woman. There are only n 2 possible proposals ▪

6 Proof of Correctness: Perfection Claim: All men and women get matched. Why? –Pf: (by contradiction) Suppose, for sake of contradiction, that Zeus is not matched upon termination of algorithm Then some woman, say Amy, is not matched upon termination By Observation 2, Amy was never proposed to But, Zeus proposes to everyone – contradiction!▪ Hence, the algorithm finds a perfect matching

7 Proof of Correctness: Stability Claim: There are no unstable pairs in S* Pf: (by contradiction) –Suppose A-Z is an unstable pair: each prefers each other to the partner in Gale-Shapley matching S* –Case 1: Z never proposed to A  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  A-Z is stable –In either case A-Z is stable, a contradiction ▪ Bertha-Zeus Amy-Yancey S*... men propose in decreasing order of preference –Obs 1 women only trade up

8 Result Simple, O(n 2 ) algorithm to compute a stable matching Corollary –A stable matching always exists

9 Understanding the Solution For a given problem instance, there may be several stable matchings: m 1 : w 1 w 2 w 3 m 2 : w 2 w 3 w 1 m 3 : w 3 w 1 w 2 w 1 : m 2 m 3 m 1 w 2 : m 3 m 1 m 2 w 3 : m 1 m 2 m 3 m1m1 m2m2 m3m3 w1w1 w2w2 w3w3 How many stable matchings can you find?

10 Understanding the Solution Q: Do all executions of Gale-Shapley yield the same stable matching? If so, which one? m 1 : w 1 w 2 w 3 m 2 : w 1 w 3 w 2 m 3 : w 1 w 2 w 3 w 1 : m 2 m 3 m 1 w 2 : m 3 m 1 m 2 w 3 : m 3 m 1 m 2 m1m1 m2m2 w2w2 w1w1 m3m3 w3w3

11 Understanding the Solution Stable matchings are not necessarily fair Many different ways of picking m’s to propose Surprising result: –All executions (orderings of picking free m’s) in G-S approach give the same result

12 Understanding the Solution Proposal Algorithm (G-S algorithm) finds the best possible solution for M (i.e., there is no stable matching in which any of the men could have hoped to do better) Formalize the notion of best possible solution –(m, w) is valid if (m, w) is in some stable matching –best(m): the highest ranked w for m, such that (m, w) is valid (i.e., there is no w ' such that w ' ranks higher than w and (m, w ') is valid) –S* = {(m, best(m)} –Every execution of the proposal algorithm computes S* (proof in page 11 of the book) uniqueness

13 Understanding the Solution Related result: Proposal algorithm yields the worst valid partner for the W’s ( i.e., for each w, (w,m) is valid (i.e. there is a stable matching containing the pair (w,m) ) and no m’ that w ranks lower is a valid partner) Algorithm is the M-optimal algorithm Proposal algorithms where w’s propose is W- optimal

14 Let’s prove that the algorithm gives the worst valid partner for each w Lemma: In the stable matching S*, each woman is paired with her worst valid partner. Proof in class –Sketch -- do by contradiction; assume there is a pair (m,w) in S* such that m is not the worst valid partner –Then there is a stable matching S’ in which w is paired with a man m’, whom she likes less than m –What can we say about m in S’ ( he must be paired with a woman w’, (m,w’) is valid and since (m,w) is in S*, w is the best valid partner for m; consequently m prefers w to w’) –We can see that S’ is unstable --- Why??? –Contradiction --- Why??

15 Key Ideas/Steps in Algorithm Design as exemplified in this sample problem: Formalize real world problem –Model: graph and preference lists –Mechanism: stability condition Specify an algorithm with a natural operation –e.g. Proposal in G-S Establish termination of process through invariants and progress measure Underspecify an algorithm –e.g. in G-S as long as there is a free man one can choose any free man) Establish uniqueness of solution

16 A Landscape of Representative Problems Show the types of problems we will consider We’ll see that similar looking problems can have very different characteristics and require different methods Problems –Interval Scheduling –Weighted Interval Scheduling –Bipartite Matching –Maximum Independent Set –Competitive Facility Location

17 Interval Scheduling Input: Set of jobs with start and finish times Goal: Find maximum cardinality subset of mutually compatible jobs ( nlogn greedy algorithm) Time 01234567891011 f g h e a b c d h e b jobs don't overlap

18 Weighted Interval Scheduling Input: Set of jobs with start, finish, and weights Goal: Find maximum weight subset of mutually compatible jobs Time 01234567891011 20 11 16 13 23 12 20 26 n log n dynamic programming algorithm

19 Bipartite Graph A graph G = (V, E) is bipartite if V can be partitioned into sets X and Y such that every edge in E has one end in X and the other end in Y

20 Bipartite Graph C 1 5 2 A E 3 B D4

21 Many relationships are expressed by a bipartite graph C 1 5 2 A E 3 B D4 professors courses can teach

22 Bipartite Matching Input: Bipartite graph Goal: Find maximum cardinality matching –A matching is M  E with property that each node in V appears in at most one edge of M

23 Find a Maximum Matching Solutions use max-flow based algorithms (Polynomial time)

24 Independent Set Problem Input: Graph Goal: Find maximum cardinality independent set 6 2 5 1 7 3 4 6 5 1 4 subset of nodes such that no two joined by an edge

25 Find a Maximum Independent Set NP-complete No efficient algorithm is known, and it is conjectured that no such algorithm exists

26 Key characteristics of the Independent Set Problem Hard to find a solution Easy to verify a solution once you have one Can encode interval scheduling and bipartite matching problems as Independent Set problems Other problems like this –Hamiltonian cycle –Traveling salesman –3-Sat –Graph coloring

27 NP-Completeness Theory of Hard Problems (like the independent set problem) A large number of problems are known to be equivalent Very elegant theory

28 Are There Even Harder Problems? Simple game: –Players alternating selecting nodes in a graph Score points associated with node Once node is picked, remove node’s neighbors –When neither can move, player with most points wins

29 Another Game: Competitive Facility Location For a particular player P i, is there a strategy so that, no matter how the other players play, P i will be able to select a set of nodes with a total value of at least X? Hard to convince someone of the answer to this question (i.e., no short proof, lengthy case-by-case analysis), compare with Independent Set Problem PSPACE-complete

30 Competitive Facility Location PSPACE-complete problems are believed to be strictly harder than NP-complete problems as there does not appear to be a short proof if there is a solution For many problems that involve game playing and planning, it seems that one must do a lengthy case-by- case analysis of the set of possible moves.

31 Theorem: Output of G-S Algorithm is S* {(m,best(m)) for all m} Proof Sketch: By contradiction – (what do we say??)

32 Assume in output of G-S there is some man who is not paired with his best valid partner – (What does this imply?)

33 (Because men propose in decreasing order of preference) some man m is rejected by a valid partner; Consider the first time in execution this happens; let m be this man who is rejected by a valid partner, w Then w must be best(m) (Why – again because m proposes in order of preference.) Now focus on w

34 w now forms or continues an engagement with m’, who she prefers to m Also there is a stable matching S’ containing the pair (m,w) ( since w is a valid partner of m) Who is m’ paired with in this S’? It can’t be w, so let it be w’ not equal to w We can show that (m’,w’) is unstable –m’ prefers w to w’ (m’ proposed in order of preference) –and w prefers m’ to m (see above) Conclude that S’ is not a stable matching A contradiction!!! Conclude in output of G-S: for all men m, m is paired with best(m)


Download ppt "CSCI 256 Data Structures and Algorithm Analysis Lecture 2 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some."

Similar presentations


Ads by Google