Você está na página 1de 39

Bipartite Matching

Lecture 8: Oct 7

This Lecture
Graph matching is an important problem in graph theory.
It has many applications and is the basis of more advanced problems.
In the last lecture we consider the stable matching problem.
Today we will study the bipartite matching problem.
Problem and Halls theorem
Reductions and Applications
Proof of Halls theorem (optional)

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 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 (i.e. of degree 1).
The perfect matching problem: Is there a perfect matching?
Once you know how to solve perfect matching, you can also do maximum matching.

Examples
Which bipartite graphs have a perfect matching?

Examples
Which bipartite graphs have a perfect matching?

Working for the King


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 (i.e. there is really no perfect matching, not because you
are incompetent)?
One attempt is to try all the possibilities and show that none works,
but you can imagine the King wont have the time and patience for that.
Is that a smarter way? It is difficult to argue that no solution exists.

Examples
Which bipartite graphs have a perfect matching?

Some Notation

N(S)
S

Let S be a subset of vertices on one side,


and |S| be the number of vertices in S.
Let N(S) be the neighbours of vertices in S, i.e.
a vertex v belongs to N(S) iff v is a neighbor of some vertex in S.
Let |N(S)| be the number of vertices in N(S).

A Necessary Condition

N(S)
S

If |N(S)| < |S| for some S, then it is impossible to have a perfect matching.
In other words, in order to have a perfect matching,
a necessary condition is that for all subsets S on one side,
we must have |N(S)| >= |S|.

Halls Theorem
Is it the only situation when a bipartite graph does not have a perfect matching?
Hall said yes in 1935.

Halls 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
for every subset S of W.
This is a deep theorem.
It characterizes exactly when a bipartite graph
does not have a perfect matching.
(Now you can convince the king.)

This Lecture

Problem and Halls theorem


Reductions and Applications
Proof of Halls theorem (optional)

Application 1: Job Assignment


Job Assignment Problem:
There are n persons and n jobs.
Each person is willing to do a subset of jobs.
Can you find an assignment so that all jobs are taken care of
while everyone is responsible for at most one job?

Leo

Marking

Hackson

Tutorials

Jesse

Solutions

Tom

Newsgroup

A perfect matching corresponds to a perfect assignment.

Application 1: Job Assignment


Job Assignment Problem:
There are n persons and n jobs.
Each person is willing to do a subset of jobs.
Can you find an assignment so that all jobs are taken care of
while everyone is responsible for at most one job?
We can model the job assignment problem as a bipartite matching problem.
We create a vertex for each person, and we create a vertex for each job.
If a person is willing to do a job, then we add an edge between them.
Then a perfect matching corresponds to a perfect assignment.
This problem can be generalized to give different workload to each person.
In fact, there is an efficient algorithm to find such as assignment! (CSC 3160)

Application 2: Domino Puzzle

Can you fill a (incomplete) chessboard perfectly with dominos?

Application 2: Domino Puzzle

Create 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 2: Domino Puzzle

This is another example where we can model a problem as a graph problem.

Application 3: Partial Latin Square


Latin Square: an 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 3: Partial Latin Square


Suppose you are given a partial Latin Square when some rows are already filled in.

Can you always extend it to a Latin Square?


Using bipartite matching, we can prove that the answer is yes.
The proof consists of two steps:
(1) Reduce the problem into a bipartite matching problem.
(2) Prove that the bipartite matching problem always has a solution by Halls theorem.

Step 1: Reduction to Bipartite Matching


First, we reduce the problem to a bipartite matching problem.
Given a partial Latin square, we construct a bipartite graph to fill in the next row.

column

number

We want to match the numbers to the columns.


Create 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.

Step 1: Reduction to Bipartite Matching


Given a partial Latin square, we construct a bipartite graph to fill in the next row.

column

3
number

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 Halls Theorem


Halls 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 Halls Theorem


Halls 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 Halls Theorem


Halls 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 Halls theorem,
we need to verify |N(S)| >= |S| for every subset S.
Proof by contradiction:
1. Suppose there is a subset S with |S| > |N(S)|.
2. All the edges from S go to N(S).
S

N(S)

3. There are total k|S| edges from S to N(S).


4. But the total degree of N(S) is k|N(S)| < k|S|.
5. A contradiction.

Step 2: Completing Latin Square


Claim: Every k-regular bipartite graph has a perfect matching.

column

number

The bipartite graphs coming from Latin square are always regular because:
Suppose there are k unfilled rows.
Then each column has n-k distinct 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.

More Applications (Optional)


The bipartite matching problem is an important problem and has many applications.
One important application is the maximum flow problem.

This is to find the maximum number of edge disjoint paths between two nodes.
This can be applied to find the maximum amount of information one can send
from one point in the network to another point in the network.
This problem can be reduced to the bipartite matching problem (CSC 3160).

This Lecture

Problem and Halls theorem


Reductions and Applications
Proof of Halls theorem (optional)

Proof of Halls Theorem (easy direction)


Halls 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.

N(S)

Just consider the neighbours of S in the perfect matching.

Proof of Halls Theorem (difficult direction)


Halls 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| for all 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 Halls Theorem


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

Proof of Halls Theorem


Halls Theorem: If |N(S)| >= |S| for every subset S of V,
then there is a perfect matching.
Case 2: Suppose there is a proper 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

G2

Then we are done.

N(S)

S
Find a perfect matching in G2 by induction.

Proof of Halls Theorem


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

T
G2

|N(T)

G 2| >= |T|.

G2|
N(S)

Proof of Halls Theorem


Why there is a perfect matching in G2?
For any subset T
Hence, |N(T)

S, N(T) is contained in G 2.
G2| = |N(T)| >= |T|.

Therefore, by induction, there is a perfect matching in G 2.

T
G2

|N(T)

G2|
N(S)

S
Find a perfect matching in G2 by induction.

Proof of Halls Theorem


Why there is a perfect matching in G1?
For any subset T, we want to show |N(T)

G 1| >= |T| to apply induction.

1. Consider T, by assumption, |N(T)| >= |T|


2. Can we conclude that |N(T)

G1| >= |T|?

Now what?

3. No, because N(T) may intersect N(S)!

N(T)

G1

N(S)

Proof of Halls Theorem


Why there is a perfect matching in G1?
For any subset T, we want to show |N(T)
1. Consider S

T, by assumption, |N(S

2. Since |S|=|N(S)|, |N(S


3. So |N(T)

G1| = |N(S

G 1| >= |T| to apply induction.

T)| >= |S

T) N(S)| >= |S
T) N(S)| >= |S

T| (the green areas).

T - S| (the red areas).


T S| = |T|, as required.

N(T)
N(S

|S|=|N(S)|

G1 (red)
T) (green)
N(S)

Proof of Halls Theorem


Halls 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

G2

Now we are done.

N(S)

S
Find a perfect matching in G2 by induction.

Bipartite Matching and Halls Theorem

Halls theorem is a fundamental theorem in graph theory.


In this course, it is important to learn
1. how to use bipartite matching to solve problems, and
2. how to apply Halls theorem.
The proof of Halls theorem is optional.

Você também pode gostar