15 251 great theoretical ideas in computer science
play

15-251 Great Theoretical Ideas in Computer Science Lecture 11: - PowerPoint PPT Presentation

15-251 Great Theoretical Ideas in Computer Science Lecture 11: Graphs III: Maximum and Stable Matchings October 8th, 2015 Todays Goal: Save lives. Todays Goal: Maximum matching problem (in bipartite graphs) Stable matching problem


  1. 15-251 Great Theoretical Ideas in Computer Science Lecture 11: Graphs III: Maximum and Stable Matchings October 8th, 2015

  2. Today’s Goal: Save lives.

  3. Today’s Goal: Maximum matching problem (in bipartite graphs) Stable matching problem

  4. Maximum matching problem (in bipartite graphs)

  5. Some motivating real-world examples matching machines and jobs Job 1 Job 2 . . . . . . Job n

  6. Some motivating real-world examples matching professors and courses 15-110 15-112 15-122 15-150 15-251 . . . . . .

  7. Some motivating real-world examples matching students and internships

  8. Some motivating real-world examples matching kidney donors and patients

  9. How do you solve a problem like this? 1. Formulate the problem 2. Ask : Is there a trivial algorithm? 3. Ask : Is there a better algorithm? 4. Find and analyze

  10. Bipartite Graphs X Y not allowed is bipartite if: G = ( V, E ) - there exists a bipartition and of X Y V - each edge connects a vertex in to a vertex in X Y Given a graph , we could ask, is it bipartite? G = ( V, E )

  11. Bipartite Graphs Given a graph , we could ask, is it bipartite? G = ( V, E ) 1 1 1 2 2 5 3 2 3 3 4 4

  12. Bipartite Graphs X Y Sometimes we write the bipartition explicitly: G = ( X, Y, E )

  13. Bipartite Graphs Great for modeling relations between two classes of objects. Examples: = machines, = jobs X Y An edge means is capable of doing . { x, y } x y = professors, = courses X Y An edge means can teach . { x, y } x y = students, = internship jobs X Y An edge means and are interested in each other. { x, y } x y …

  14. Matchings in bipartite graphs Often, we are interested in finding a matching in a bipartite graph X Y A matching : A subset of the edges that do not share an endpoint.

  15. Matchings in bipartite graphs Often, we are interested in finding a matching in a bipartite graph X Y matching A matching : A subset of the edges that do not share an endpoint.

  16. Matchings in bipartite graphs Often, we are interested in finding a matching in a bipartite graph X Y matching A matching : A subset of the edges that do not share an endpoint.

  17. Matchings in bipartite graphs Often, we are interested in finding a matching in a bipartite graph X Y not a matching A matching : A subset of the edges that do not share an endpoint.

  18. Matchings in bipartite graphs Often, we are interested in finding a matching in a bipartite graph X Y maximum matching Maximum matching : a matching with largest number of edges (among all possible matchings).

  19. Matchings in bipartite graphs Often, we are interested in finding a matching in a bipartite graph X Y Cannot add maximal more edges. matching “Local optimum” Maximal matching : a matching which cannot contain any more edges.

  20. Matchings in bipartite graphs Often, we are interested in finding a matching in a bipartite graph X Y perfect a necessary matching condition for perfect matching: | X | = | Y | Perfect matching : a matching that covers all vertices.

  21. Important Note We can define matchings for non-bipartite graphs as well.

  22. Important Note We can define matchings for non-bipartite graphs as well.

  23. Maximum matching problem The problem we want to solve is: Maximum matching problem Input : A graph . G = ( V, E ) Output : A maximum matching in . G The restriction where G is bipartite is already interesting!

  24. Bipartite maximum matching problem The problem we want to solve is: Bipartite maximum matching problem Input : A bipartite graph . G = ( X, Y, E ) Output : A maximum matching in . G

  25. How do you solve a problem like this? 1. Formulate the problem 2. Ask : Is there a trivial algorithm? 3. Ask : Is there a better algorithm? 4. Find and analyze

  26. Bipartite maximum matching problem Bipartite maximum matching problem Input : A bipartite graph . G = ( X, Y, E ) Output : A maximum matching in . G Is there a (trivial) algorithm to solve this problem? Try all possible subsets of the edges. Check if it is a matching. Keep track of the maximum one found. Running time: Ω (2 m )

  27. How do you solve a problem like this? 1. Formulate the problem 2. Ask : Is there a trivial algorithm? 3. Ask : Is there a better algorithm? 4. Find and analyze

  28. Bipartite maximum matching problem What if we picked edges greedily?

  29. Bipartite maximum matching problem What if we picked edges greedily?

  30. Bipartite maximum matching problem What if we picked edges greedily?

  31. Bipartite maximum matching problem What if we picked edges greedily? maximal matching but not maximum Is there a way to get out of this local optimum?

  32. Augmenting paths Let M be some matching. An augmenting path with respect to M is a path in G such that: - the edges in the path alternate between being in M and not being in M - the first and last vertices are not matched by M 1 5 Augmenting path: 2 6 4-8-2-5-1-7 3 7 4 8

  33. Augmenting paths 1 5 Augmenting path: 2 6 4-8-2-5-1-7 3 7 4 8 4 8 2 5 1 7 4 8 2 5 1 7 augmenting path can obtain a bigger matching. ⇒ =

  34. Augmenting paths and maximum matchings augmenting path can obtain a bigger matching. ⇒ = In fact, it turns out: no augmenting path maximum matching. ⇒ = Theorem: A matching M is maximum if and only if there is no augmenting path with respect to M .

  35. Augmenting paths and maximum matchings Proof: If there is an augmenting path with respect to M , we saw that M is not maximum. Want to show: If M is not maximum, then there is an augmenting path. Let M* be a maximum matching. | M* | > | M |. Let S be the set of edges 1 5 contained in M* or M 2 6 but not both. 3 7 S = ( M* M ) - ( M M* ) 4 8 ∩ ∪

  36. Augmenting paths and maximum matchings Proof: 1 5 Let S be the set of edges contained in M* or M 2 6 but not both. 3 7 S = ( M* M ) - ( M M* ) 4 8 ∩ ∪ (will find an augmenting path in S ) What does S look like? Each vertex has degree at most 2. (why?) So S is a collection of cycles and paths. (exercise) The edges alternate red and blue .

  37. Augmenting paths and maximum matchings Proof: 1 5 Let S be the set of edges contained in M* or M 2 6 but not both. 3 7 S = ( M* M ) - ( M M* ) 4 8 ∩ ∪ So S is a collection of cycles and paths. (exercise) The edges alternate red and blue . # red > # blue in S # red = # blue in cycles So a path with # red > # blue. ∃ This is an augmenting path with respect to M .

  38. Algorithm to find maximum matching Theorem: A matching M is maximum if and only if there is no augmenting path with respect to M . Algorithm: - Start with a single edge as your matching M . - Repeat until there is no augmenting path w.r.t. M : - Find an augmenting path with respect to M . - Update M according to the augmenting path. OK, but how do you find an augmenting path? Exercise (homework?)

  39. Algorithm to find maximum matching Theorem: A matching M is maximum if and only if there is no augmenting path with respect to M . Algorithm: - Start with a single edge as your matching M . - Repeat until there is no augmenting path w.r.t. M : - Find an augmenting path with respect to M . - Update M according to the augmenting path. O ( m · n ) time algorithm in bipartite graphs.

  40. Today’s Goal: Maximum matching problem (in bipartite graphs) Stable matching problem

  41. Stable matching problem

  42. Finding internship

  43. Finding internship 1. Alice 1. 2. Bob 3. Charlie 2. 4. David 3. 4. . . . 1. Bob 2. David Other examples: 3. Alice medical residents - hospitals 4. Charlie students - colleges

  44. Finding internship What can go wrong? Alice Macrosoft Bob Moogle Charlie Umbrella David KLG Suppose Alice gets “matched” with Macrosoft. Charlie gets “matched” with Umbrella. But, say, Alice prefers Umbrella over Macrosoft and Umbrella prefers Alice over Charlie.

  45. Finding internship: Formalizing the problem An instance of the problem can be represented as a complete bipartite graph + preference list of each node . X Y (e,f,h,g) a e (a,b,c,d) (e,g,h,f) b f (a,b,c,d) (e,h,f,g) c g (a,b,c,d) (e,f,g,h) d h (a,b,c,d) Students Companies | X | = | Y | = n Goal : Find a stable matching.

  46. Finding internship: Formalizing the problem What is a stable matching? X Y (e,f) a e (a,b) (e,f) b f (a,b) 1. It has to be a perfect matching. 2. Cannot contain an unstable pair: A pair (x, y) not matched but they prefer each other over their current partners.

  47. Finding internship: Formalizing the problem What is a stable matching? X Y (e,f) a e (a,b) (e,f) b f (a,b) (a, e) is an unstable pair. 1. It has to be a perfect matching. 2. Cannot contain an unstable pair: A pair (x, y) not matched but they prefer each other over their current partners.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend