04/12/2005 Tucker, Sec. 4.4 1
Applied Combinatorics, 4th Ed.Alan Tucker
Section 4.4
Algorithmic Matching
Prepared by Joshua Schoenly and Kathleen McNamara
04/12/2005 Tucker, Sec. 4.4 2
Some Definitions
X-Matching - All vertices in X are used
Maximal Matching - The largest possible number of independent edges
Note: an X-matching is necessarily maximal.
Matching - a set of independent edges
X Y
Note: independent edges refer to edges that do not share a common vertex
04/12/2005 Tucker, Sec. 4.4 3
More Definitions
Edge Cover
A set of vertices so that every edge is incident to
at least one of them
R(A)
Range of a set A of vertices
R(A) is the set of vertices adjacent to at least one vertex in A
A = red, R(A) = green
04/12/2005 Tucker, Sec. 4.4 4
Matching Network
za
All edges infinite capacity
All edges capacity 1
By converting the bipartite graph to a network, we can use network flow techniques to find matchings.
04/12/2005 Tucker, Sec. 4.4 5
Matching Network
Matching a – z flow
za
X – matching saturation at a
za
04/12/2005 Tucker, Sec. 4.4 7
Matching Network
Edge cover Finite a – z cut
za
A = red on left, B = red on right
S = red vertices, an edge cover
P = a, black on left, red on right
P = z, red on left, black on right
Edge cover means that all edges have at least one red endpoint:
P to P, to , to P.
Thus only uncovered edges, would go from P to .
P P P
P
04/12/2005 Tucker, Sec. 4.4 8
Matching Network
Not an edge cover Infinite a – z cut
za
A = red on left, B = red on right
S = red vertices, NOT an edge cover
P = a, black on left, red on right
P = z, red on left, black on right
An infinite cut would go through an edge with two black endpoints, which corresponds to an uncovered edge.
04/12/2005 Tucker, Sec. 4.4 9
Theorem 1Recall Corollary 2a from Section 4.3:
The size of a maximal flow is equal to the capacity of a minimal cut.
Since….
Then,
The size of a maximal matching is equal
to the size of a minimal edge cover.
Edge cover Finite a – z cut
Matching a – z flow
and
04/12/2005 Tucker, Sec. 4.4 10
Finding Matchings
za
Take any matching, convert to a network, and then use the augmenting flow algorithm to find a maximal flow, hence a
maximal matching.
04/12/2005 Tucker, Sec. 4.4 11
An easy way to think about it
1. Start with any matching.
2. From an unmatched vertex in X, alternate between non-matching and matching edges until you hit an unmatched vertex in Y.
3. Then switch between the non-matching and matching edges along to path to pick up one more matching edge.
4. Continue this until no unmatched vertex in X leads to an unmatched vertex in Y.
04/12/2005 Tucker, Sec. 4.4 12
Example
Start with any matching
Find an alternating path
Start at an unmatched vertex
in X
End at an unmatched vertex
in Y
Switch matching to non-matching and vice versa
A maximal matching!
Note: if this does not result in a maximal matching, start from step one and do it again.
04/12/2005 Tucker, Sec. 4.4 13
Theorem 2Hall’s Marriage Theorem
A bipartite graph has an X-matching if and only if for every subset A of X, the number of vertices in R(A) is greater
than or equal to the number of vertices in A.
X – matching
True for all A in X
A is the set of red vertices
R(A) is the set of blue vertices
04/12/2005 Tucker, Sec. 4.4 14
Proof ofHall’s Marriage Theorem
“ ”: An X-matching implies that for every subset A of X, |R(A)| is greater than or equal to |A|.
X – matching For any A, the X – matching gives
at least one vertex in R(A) for every vertex in A.
04/12/2005 Tucker, Sec. 4.4 15
Proof ofHall’s Marriage Theorem
“ ”: If |R(A)| is greater than or equal to |A| for every subset A of X, then there is an X-matching.
• First note that if M is a maximal matching, then .
• Taking A = X, we have that since the range of X is contained in Y. Thus .
• Also, by Theorem 1, if S is a minimal edge cover, then .
• Note that if , then M must be an X – matching.
• Thus, it suffices to show that for all edge covers S.
min X , YM
M S
X X YR XM
XM
X S
04/12/2005 Tucker, Sec. 4.4 16
Since , .
Now let A be the vertices in X but not in S, so that .
Thus, .
Now, S is an edge-cover, so if it doesn’t contain on the X side, it must contain all the vertices a goes to on the Y side in order to cover the edges in between. Thus , so .
Thus,
But , hence ,
so as needed. QED
Proof of Hall’s Marriage Theorem“ ”: Continued… we need to show that for all
edge covers S. X S
S S X S Y S S X S Y
S X X A
S S X S Y X A S Y
a A
R A S Y R A S Y
S X A S Y X A R A
0A R A A R A
S X A R A X
A
S
R(A)
04/12/2005 Tucker, Sec. 4.4 17
Class ProblemProblem #7
In the following table of remaining games, is it possible for the Bears to be champions (or co-champions) if they win all remaining games? Build the appropriate network model.
Team Wins to Date
Games to Play
With Bears
With Lions
With Tigers
With Vampires
Bears 26 14 -- 4 4 6
Lions 34 5 4 -- 0 1
Tigers 32 8 4 0 -- 4
Vampires 29 11 6 1 4 --
04/12/2005 Tucker, Sec. 4.4 18
Class ProblemProblem #7
In the following table of remaining games, is it possible for the Bears to be champions (or co-champions) if they win all remaining games? Build the appropriate network model.
Team Wins to Date
Games to Play
With Bears
With Lions
With Tigers
With Vampires
Bears 26 14 -- 4 4 6
Lions 34 1 4 -- 0 1
Tigers 32 4 4 0 -- 4
Vampires 29 5 6 1 4 --
04/12/2005 Tucker, Sec. 4.4 19
Solution to Class Problem
6,1
8,0
11,4
∞,0
1,1
4,4
0,0∞,1 ∞,0
∞,0 ∞,0
∞,4
a z
TV
LV
LTL
T
V