Matching Lecture 19: Nov 23.

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.
CS 336 March 19, 2012 Tandy Warnow.
Great Theoretical Ideas in Computer Science
Tutorial 5 of CSCI2110 Eulerian Path & Hamiltonian Cycle Tutor: Zhou Hong ( 周宏 )
Naveen Garg, CSE, IIT Delhi
Matching Theory.
Bipartite Matching, Extremal Problems, Matrix Tree Theorem.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Great Theoretical Ideas in Computer Science for Some.
1 Discrete Structures & Algorithms Graphs and Trees: III EECE 320.
Introduction to Graph Theory Lecture 11: Eulerian and Hamiltonian Graphs.
Playing Fair at Sudoku Joshua Cooper USC Department of Mathematics.
Tutorial 6 of CSCI2110 Bipartite Matching Tutor: Zhou Hong ( 周宏 )
1 Weighted Bipartite Matching Lecture 4: Jan Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight.
1 Discrete Structures & Algorithms Graphs and Trees: IV EECE 320.
Great Theoretical Ideas in Computer Science.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
Approximation Algorithms: Combinatorial Approaches Lecture 13: March 2.
CS5371 Theory of Computation
Great Theoretical Ideas in Computer Science.
Chapter 26 of CLSR Bipartite Matching By Dr. M. Sakalli, Sources: Levitin and many other CSE, Marmara Univ. May/2009.
Graph Colouring Lecture 20: Nov 25.
1 Bipartite Matching Lecture 3: Jan Bipartite Matching A graph is bipartite if its vertex set can be partitioned into two subsets A and B so that.
1 Bipartite Matching Polytope, Stable Matching Polytope x1 x2 x3 Lecture 10: Feb 15.
Matching Polytope, Stable Matching Polytope Lecture 8: Feb 2 x1 x2 x3 x1 x2 x3.
Chapter 10: Iterative Improvement Simplex Method The Design and Analysis of Algorithms.
The Stable Marriage Problem
 Jim has six children.  Chris fights with Bob,Faye, and Eve all the time; Eve fights (besides with Chris) with Al and Di all the time; and Al and Bob.
CSE, IIT KGP Matchings and Factors. CSE, IIT KGP Matchings A matching of size k in a graph G is a set of k pairwise disjoint edges.A matching of size.
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.
7 Graph 7.1 Even and Odd Degrees.
10.4 How to Find a Perfect Matching We have a condition for the existence of a perfect matching in a graph that is necessary and sufficient. Does this.
Lecture 22 More NPC problems
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
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.
Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar.
Stable Matchings a.k.a. the Stable Marriage Problem
Great Theoretical Ideas in Computer Science.
1 The Stable Marriage Problem Algorithms and Networks 2014/2015 Hans L. Bodlaender Johan M. M. van Rooij.
All Pair Shortest Path IOI/ACM ICPC Training June 2004.
Graph Colouring L09: Oct 10. This Lecture Graph coloring is another important problem in graph theory. It also has many applications, including the famous.
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)
Bipartite Matching. Unweighted Bipartite Matching.
5.8 Graph Matching  Example: Set of worker assign to a set of task  Four tasks are to be assigned to four workers.  – Worker 1 is qualified to do tasks.
Graph Colouring Lecture 20: Nov 25. This Lecture Graph coloring is another important problem in graph theory. It also has many applications, including.
Introduction to Graphs. This Lecture In this part we will study some basic graph theory. Graph is a useful concept to model many problems in computer.
The Stable Marriage Problem
Graph Algorithms Maximum Flow - Best algorithms [Adapted from R.Solis-Oba]
Introduction to Graph Theory
CSCI 256 Data Structures and Algorithm Analysis Lecture 2 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
Introduction to Graph Theory
Indian Institute of Technology Kharagpur PALLAB DASGUPTA Graph Theory: Matchings and Factors Pallab Dasgupta, Professor, Dept. of Computer Sc. and Engineering,
Hamiltonian Graphs Graphs Hubert Chan (Chapter 9.5)
מתמטיקה בדידה Discrete Math Lecture 12 1 TexPoint fonts used in EMF.
Matching Boys Girls A B C D E
Cybernetica AS & Tartu University
Chapter 10 Iterative Improvement
Bipartite Matching Lecture 8: Oct 7.
Hamiltonian Graphs Graphs Hubert Chan (Chapter 9.5)
Algorithms and Networks
Maximum Flow - Best algorithms
Great Theoretical Ideas in Computer Science
Discrete Mathematics for Computer Science
Computational Processes II
Systems of distinct representations
Computational Processes II
Piyush Kumar (Lecture 3: Stable Marriage)
Presentation transcript:

Matching Lecture 19: Nov 23

This Lecture Graph matching is an important problem in graph theory. It has many applications and is the basis of more advanced problems. In this lecture we will cover two versions of graph matching problems. Stable matching Bipartite matching

Matching 1 2 3 4 5 Boys Girls A B C D E 1 2 3 4 5 Boys Girls A B C D E Today’s goal: to “match” the boys and the girls in a “good” way.

Matching Today’s goal: to “match” the boys and the girls in a “good” way. What is a matching? Each boy is married to at most one girl. Each girl is married to at most one boy. Depending on the information we have. What is a good matching? A stable matching: They have no incentive to break up… A maximum matching: To maximize the number of pairs married…

Stable Matching The Stable Marriage Problem: There are n boys and n girls. For each boy, there is a preference list of the girls. For each girl, there is a preference list of the boys. Boys Girls 1: CBEAD A : 35214 2 : ABECD B : 52143 3 : DCBAE C : 43512 4 : ACDBE D : 12345 5 : ABDEC E : 23415

Stable Matching What is a stable matching? Consider the following matching. It is unstable, why? Boys Girls 1: CBEAD A : 35214 2 : ABECD B : 52143 3 : DCBAE C : 43512 4 : ACDBE D : 12345 5 : ABDEC E : 23415

Stable Matching Boy 4 prefers girl C more than girl B (his current partner). Girl C prefers boy 4 more than boy 1 (her current partner). So they have the incentive to leave their current partners, and switch to each other, we call such a pair an unstable pair. Boys Girls 1: CBEAD A : 35214 2 : ABECD B : 52143 3 : DCBAE C : 43512 4 : ACDBE D : 12345 5 : ABDEC E : 23415

Stable Matching What is a stable matching? A stable matching is a matching with no unstable pair, and every one is married. Can you find a stable matching in this case? Boys Girls 1: CBEAD A : 35214 2 : ABECD B : 52143 3 : DCBAE C : 43512 4 : ACDBE D : 12345 5 : ABDEC E : 23415

Stable Matching Does a stable matching always exists? Not clear… Can you find a stable matching in this case? Boys Girls 1: CBEAD A : 35214 2 : ABECD B : 52143 3 : DCBAE C : 43512 4 : ACDBE D : 12345 5 : ABDEC E : 23415

Stable Roommate The Stable Roommate Problem: There are 2n people. There are n rooms, each can accommodate 2 people. Each person has a preference list of 2n-1 people. Find a stable matching (match everyone and no unstable pair). Does a stable matching always exist? Not clear… When is it difficult to find a stable matching? Idea: triangle relationship!

Stable Roommate Idea: triangle relationship! a prefers b more than c b prefers c more than a c prefers a more than b no one likes d So let’s say a is matched to b, and c is matched to d. Then b prefers c more than a, and c prefers b more than d. No stable matching exists!

Stable Matching Can you now construct an example where there is no stable marriage? Nope… Gale,Shapley [1962]: There is always a stable matching in the stable marriage problem. This is more than a solution to a puzzle: College Admissions (original Gale & Shapley paper, 1962) Matching Hospitals & Residents. Matching Dancing Partners. The proof is based on a marriage procedure…

Stable Matching Why stable marriage is easier than stable roommate? Intuition: It is enough if we only satisfy one side! This intuition leads us to a very natural approach. Boys Girls 1: CBEAD A : 35214 2 : ABECD B : 52143 3 : DCBAE C : 43512 4 : ACDBE D : 12345 5 : ABDEC E : 23415

The Marrying Procedure Morning: boy propose to their favourite girl Billy Bob Brad Angelina

The Marrying Procedure Morning: boy propose to their favourite girl Afternoon: girl rejects all but favourite Billy Bob Angelina Brad

The Marrying Procedure Morning: boy propose to their favourite girl Afternoon: girl rejects all but favourite Evening: rejected boy writes off girl This procedure is then repeated until all boys propose to a different girl Billy Bob … Angelina …

Day 1 Morning: boy propose to their favourite girl Afternoon: girl rejects all but favourite Evening: rejected boy writes off girl Boys Girls 1: CBEAD A : 35214 2 : ABECD B : 52143 3 : DCBAE C : 43512 4 : ACDBE D : 12345 5 : ABDEC E : 23415

Day 2 Morning: boy propose to their favourite girl Afternoon: girl rejects all but favourite Evening: rejected boy writes off girl Boys Girls 1: CBEAD A : 35214 2 : ABECD B : 52143 3 : DCBAE C : 43512 4 : ACDBE D : 12345 5 : ABDEC E : 23415

Day 3 Morning: boy propose to their favourite girl Afternoon: girl rejects all but favourite Evening: rejected boy writes off girl Boys Girls 1: CBEAD A : 35214 2 : ABECD B : 52143 3 : DCBAE C : 43512 4 : ACDBE D : 12345 5 : ABDEC E : 23415

Day 4 Morning: boy propose to their favourite girl Afternoon: girl rejects all but favourite Evening: rejected boy writes off girl OKAY, marriage day! Boys Girls 1: CBEAD A : 35214 2 : ABECD B : 52143 3 : DCBAE C : 43512 4 : ACDBE D : 12345 5 : ABDEC E : 23415

Proof of Gale-Shapley Theorem This procedure always find a stable matching in the stable marriage problem. What do we need to check? The procedure will terminate. Everyone is married. No unstable pairs.

Step 1 of the Proof Claim 1. The procedure will terminate in at most n2 days. 1. If every girl is matched to exactly one boy, then the procedure will terminate. 2. Otherwise, since there are n boys and n girls, there must be a girl receiving more than one proposal. 3. She will reject at least one boy in this case, and those boys will write off that girl from their lists, and propose to their next favourite girl. 4. Since there are n boys and each list has at most n girls, the procedure will last for at most n2 days.

Step 2 of the Proof Claim 2. Every one is married when the procedure stops. Proof: by contradiction. If B is not married, his list is empty. That is, B was rejected by all girls. A girl only rejects a boy if she already has a more preferable partner. Once a girl has a partner, she will be married at the end. That is, all girls are married (to one boy) at the end, but B is not married. This implies there are more boys than girls, a contradiction.

Step 3 of the Proof Claim 3. There is no unstable pair. Fact. If a girl G rejects a boy B, then G will be married to a boy (she likes) better than B. Consider any pair (B,G). Case 1. If G is on B’s list, then B is married to be the best one on his list. So B has no incentive to leave. Case 2. If G is not on B’s list, then G is married to a boy she likes better. So G has no incentive to leave.

Proof of Gale-Shapley Theorem There is always a stable matching in the stable marriage problem. Claim 1. The procedure will terminate in at most n2 days. Claim 2. Every one is married when the procedure stops. Claim 3. There is no unstable pair. So the theorem follows.

More Questions (Optional) Intuition: It is enough if we only satisfy one side! Is this marrying procedure better for boys or for girls?? All boys get the best partner simultaneously! All girls get the worst partner simultaneously! Why? That is, among all possible stable matching, boys get the best possible partners simultaneously. Can a boy do better by lying? Can a girl do better by lying? NO! YES!

This Lecture Stable matching Bipartite matching

Bipartite Matching The Bipartite Marriage Problem: There are n boys and n girls. For each pair, it is either compatible or not. Goal: to find the maximum number of compatible pairs.

Bipartite Matching The Bipartite Marriage Problem: There are n boys and n girls. For each pair, it is either compatible or not. Goal: to find the maximum number of compatible pairs.

Graph Problem A graph is bipartite if its vertex set can be partitioned into two subsets A and B so that each edge has one endpoint in A and the other endpoint in B. A B A matching is a subset of edges so that every vertex has degree at most one.

Maximum Matching The bipartite matching problem: Find a matching with the maximum number of edges. A perfect matching is a matching in which every vertex is matched. The perfect matching problem: Is there a perfect matching?

Perfect Matching Does a perfect matching always exist? Of course not. Suppose you work for the King, and your job is to find a perfect matching between 200 men and 200 women. If there is a perfect matching, then you can show it to the King. But suppose there is no perfect matching, how can you convince the King this fact?

Perfect Matching Does a perfect matching always exist? Of course not. If there are more vertices on one side, then of course it is impossible. N(S) S Let N(S) be the neighbours of vertices in S. If |N(S)| < |S|, then it is impossible to have a perfect matching.

A Necessary and Sufficient Condition Is it the only situation when a bipartite graph does not have a perfect matching? Hall’s Theorem: A bipartite graph G=(V,W;E) has a perfect matching if and only if |N(S)| >= |S| for every subset S of V and W. This is a deep theorem. It tells you exactly when a bipartite graph does not have a perfect matching. (Now you can convince the king.)

Application of Bipartite Matching Leo Hackson Jesse Tom Marking Tutorials Solutions Newsgroup Job Assignment Problem: Each person is willing to do a subset of jobs. Can you find an assignment so that all jobs are taken care of? In fact, there is an efficient procedure to find such as assignment! (CSC 3160)

Application of Bipartite Matching Add a vertex for each square in the board. Add an edge for two squares if they are adjacent. This is a bipartite graph with the black and white squares form the two sides. A perfect matching in this graph corresponds to a perfect placement of dominos.

Application of Bipartite Matching With Hall’s theorem, now you can determine exactly when a partial chessboard can be filled with dominos.

Application of Bipartite Matching Latin Square: a nxn square, the goal is to fill the square with numbers from 1 to n so that: Each row contains every number from 1 to n. Each column contains every number from 1 to n.

Application of Bipartite Matching Suppose you are given a partial Latin Square when some rows are already filled in. Can you always extend it to a Latin Square? With Hall’s theorem, you can prove that the answer is yes.

Application of Bipartite Matching Given a partial Latin square, we construct a bipartite graph to fill in the next row. 1 2 3 4 5 column number 1 2 3 4 5 We want to “match” the numbers to the columns. Add one vertex for each column, and one vertex for each number. Add an edge between column i and color j if color j can be put in column i.

Application of Bipartite Matching Given a partial Latin square, we construct a bipartite graph to fill in the next row. 1 2 3 4 5 column 1 5 2 4 3 number 1 2 3 4 5 A perfect matching corresponds to a valid assignment of the next row. If we can always complete the next row, then by induction we are done. The key is to prove that the bipartite graph always has a perfect matching.

Using Hall’s Theorem Hall’s Theorem: A bipartite graph G=(V,W;E) has a perfect matching if and only if |N(S)| >= |S| for every subset S of V and W. A graph is k-regular if every vertex is of degree k. A 3-regular bipartite graph

Using Hall’s Theorem Hall’s Theorem: A bipartite graph G=(V,W;E) has a perfect matching if and only if |N(S)| >= |S| for every subset S of V and W. Claim: Every k-regular bipartite graph has a perfect matching. A 3-regular bipartite graph

Using Hall’s Theorem Hall’s Theorem: A bipartite graph G=(V,W;E) has a perfect matching if and only if |N(S)| >= |S| for every subset S of V and W. Claim: Every k-regular bipartite graph has a perfect matching. To prove this claim using Hall’s theorem, we need to verify |N(S)| >= |S| for every subset S. Proof by contradiction: Suppose there is a subset S with |S| > |N(S)|. All the edges from S go to N(S). There are total k|S| edges from S to N(S). There are at most k|N(S)| edges from N(S) to S. A contradiction. N(S) S

Completing Latin Square Claim: Every k-regular bipartite graph has a perfect matching. 1 2 3 4 5 column number 1 2 3 4 5 The bipartite graphs coming from Latin square are always regular because: Suppose there are k unfilled rows. Then each column already has n-k numbers, and so connected to k numbers. Each number appeared in n-k columns above, and so connected to k columns. So, the bipartite graph is k-regular, and thus always has a perfect matching.

Proof of Hall’s Theorem (easy direction) Hall’s Theorem: A bipartite graph G=(V,W;E) has a perfect matching if and only if |N(S)| >= |S| for every subset S of V. One direction is easy, if there is a perfect matching, then |N(S)| >= |S| for every subset S of V. S N(S) Just consider the neighbours of S in the perfect matching.

Proof of Hall’s Theorem (difficult direction) Hall’s Theorem: A bipartite graph G=(V,W;E) has a perfect matching if and only if |N(S)| >= |S| for every subset S of V. Another direction is more interesting, we need to show whenever |N(S)| >= |S|, then there is a perfect matching! How to prove such kind of statement? Proof by strong induction on the number of edges.

Proof of Hall’s Theorem Hall’s Theorem: If |N(S)| >= |S| for every subset S of V, then there is a perfect matching. Case 1: Every subset S has |N(S)| > |S|. (Easy case) Just delete an edge. By deleting an edge, |N(S)| can decrease by at most 1. Since |N(S)| > |S| before, we still have |N(S)| >= |S| after deleting an edge. Since the graph is smaller (one fewer edge), by induction, there is a perfect matching in this smaller graph, hence there is a perfect matching in the original graph.

Proof of Hall’s Theorem Hall’s Theorem: If |N(S)| >= |S| for every subset S of V, then there is a perfect matching. Case 2: Suppose there is a subset S with |N(S)| = |S|. Divide the graph into two smaller graphs G1 and G2 (so we can apply induction) Find a perfect matching in G1 by induction. G1 Then we are done. G2 S N(S) Find a perfect matching in G2 by induction.

Proof of Hall’s Theorem Why there is a perfect matching in G2? Hall’s Theorem: If |N(S)| >= |S| for every subset S of V, then there is a perfect matching. To apply Hall’s, we want to show for any subset T of S, |N(T) G2| >= |T|. T |N(T) G2| G2 S N(S)

Find a perfect matching in G2 by induction. Proof of Hall’s Theorem Why there is a perfect matching in G2? For any subset T S, N(T) G2 = N(T). By assumption, |N(T) G2| = |N(T)| >= |T|. Therefore, by induction, there is a perfect matching in G2. T |N(T) G2| G2 S N(S) Find a perfect matching in G2 by induction.

Proof of Hall’s Theorem Why there is a perfect matching in G1? For any subset T, we want to show |N(T) G1| >= |T| to apply induction. Consider T, by assumption, |N(T)| >= |T| Can we conclude that |N(T) G1| >= |T|? No, because N(T) may intersect N(S)! Now what? N(T) G1 T S N(S)

Proof of Hall’s Theorem Why there is a perfect matching in G1? For any subset T, we want to show |N(T) G1| >= |T| to apply induction. Consider S T, by assumption, |N(S T)| >= |S T| (the green areas). Since |S|=|N(S)|, |N(S T) – N(S)| >= |S T - S| (the red areas). So |N(T) G1| = |N(S T) – N(S)| > = |S T – S| = |T|, as required. N(T) G1 T |S|=|N(S)| S N(S)

Proof of Hall’s Theorem Hall’s Theorem: If |N(S)| >= |S| for every subset S of V, then there is a perfect matching. Case 2: Suppose there is a subset S with |N(S)| = |S|. Divide the graph into two smaller graphs G1 and G2 (so we can apply induction) Find a perfect matching in G1 by induction. G1 Now we are done. G2 S N(S) Find a perfect matching in G2 by induction.

Bipartite Matching and Hall’s Theorem Hall’s theorem is a fundamental theorem in graph theory. In this course, it is important to learn how to use bipartite matching to solve problems, and how to apply Hall’s theorem. The proof of Hall’s theorem is optional.