Part Matchings
Part Matchings
Matchings
EADS
Ernst Mayr, Harald Rcke 540/604
Matching
5
EADS 16 Denition
Ernst Mayr, Harald Rcke 542/604
Bipartite Matching
5
EADS 16 Denition
Ernst Mayr, Harald Rcke 543/604
Bipartite Matching
5
EADS 16 Denition
Ernst Mayr, Harald Rcke 544/604
17 Bipartite Matching via Flows
).
5
Proof
Max cardinality matching in G value of maxow in G
5
1
2
3
4
5
L R
G
5
EADS 17 Bipartite Matching via Flows
Ernst Mayr, Harald Rcke 546/604
Proof
Max cardinality matching in G value of maxow in G
5
1
2
3
4
5
L R
G
5
EADS 17 Bipartite Matching via Flows
Ernst Mayr, Harald Rcke 546/604
Proof
Max cardinality matching in G value of maxow in G
5
1
2
3
4
5
L R
G
5
EADS 17 Bipartite Matching via Flows
Ernst Mayr, Harald Rcke 546/604
Proof
Max cardinality matching in G value of maxow in G
5
1
2
3
4
5
L R
G
5
EADS 17 Bipartite Matching via Flows
Ernst Mayr, Harald Rcke 546/604
Proof
Max cardinality matching in G value of maxow in G
Let f be a maxow in G
of value k
5
1
2
3
4
5
L R
G
5
EADS 17 Bipartite Matching via Flows
Ernst Mayr, Harald Rcke 547/604
Proof
Max cardinality matching in G value of maxow in G
Let f be a maxow in G
of value k
5
1
2
3
4
5
L R
G
5
EADS 17 Bipartite Matching via Flows
Ernst Mayr, Harald Rcke 547/604
Proof
Max cardinality matching in G value of maxow in G
Let f be a maxow in G
of value k
5
1
2
3
4
5
L R
G
5
EADS 17 Bipartite Matching via Flows
Ernst Mayr, Harald Rcke 547/604
17 Bipartite Matching via Flows
Which ow algorithm to use?
)) = O(mn).
. P is an alternating path.
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 551/604
18 Augmenting Paths for Matchings
Proof.
If M is maximum there is no augmenting path P, because
we could switch matching and non-matching edges along P.
This gives matching M
. P is an alternating path.
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 551/604
18 Augmenting Paths for Matchings
Proof.
If M is maximum there is no augmenting path P, because
we could switch matching and non-matching edges along P.
This gives matching M
. P is an alternating path.
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 551/604
18 Augmenting Paths for Matchings
Proof.
If M is maximum there is no augmenting path P, because
we could switch matching and non-matching edges along P.
This gives matching M
. P is an alternating path.
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 551/604
18 Augmenting Paths for Matchings
Algorithmic idea:
As long as you nd an augmenting path augment your matching
using this path. When you arrive at a matching for which no
augmenting path exists you have a maximum matching.
Theorem 2
Let G be a graph, M a matching in G, and let u be a free vertex
w.r.t. M. Further let P denote an augmenting path w.r.t. M and
let M
.
The above theorem allows for an easier implementation of an augment-
ing path algorithm. Once we checked for augmenting paths starting
from u we dont have to check for such paths in future rounds.
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 552/604
18 Augmenting Paths for Matchings
Algorithmic idea:
As long as you nd an augmenting path augment your matching
using this path. When you arrive at a matching for which no
augmenting path exists you have a maximum matching.
Theorem 2
Let G be a graph, M a matching in G, and let u be a free vertex
w.r.t. M. Further let P denote an augmenting path w.r.t. M and
let M
.
The above theorem allows for an easier implementation of an augment-
ing path algorithm. Once we checked for augmenting paths starting
from u we dont have to check for such paths in future rounds.
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 552/604
18 Augmenting Paths for Matchings
Proof
w.r.t. M
starting at u.
If P
is
also augmenting path w.r.t. M ().
Let u
that
is in P, and let e be the matching
edge from M
incident to u
from u to u
with P
1
.
P
1
P
1
is augmenting path in M ().
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 553/604
18 Augmenting Paths for Matchings
Proof
w.r.t. M
starting at u.
If P
is
also augmenting path w.r.t. M ().
Let u
that
is in P, and let e be the matching
edge from M
incident to u
from u to u
with P
1
.
P
1
P
1
is augmenting path in M ().
u
P
w.r.t. M
starting at u.
If P
is
also augmenting path w.r.t. M ().
Let u
that
is in P, and let e be the matching
edge from M
incident to u
from u to u
with P
1
.
P
1
P
1
is augmenting path in M ().
u
P
w.r.t. M
starting at u.
If P
is
also augmenting path w.r.t. M ().
Let u
that
is in P, and let e be the matching
edge from M
incident to u
from u to u
with P
1
.
P
1
P
1
is augmenting path in M ().
u
P
P
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 553/604
18 Augmenting Paths for Matchings
Proof
w.r.t. M
starting at u.
If P
is
also augmenting path w.r.t. M ().
Let u
that
is in P, and let e be the matching
edge from M
incident to u
from u to u
with P
1
.
P
1
P
1
is augmenting path in M ().
u
u
e
P
P
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 553/604
18 Augmenting Paths for Matchings
Proof
w.r.t. M
starting at u.
If P
is
also augmenting path w.r.t. M ().
Let u
that
is in P, and let e be the matching
edge from M
incident to u
from u to u
with P
1
.
P
1
P
1
is augmenting path in M ().
u
u
e
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 553/604
18 Augmenting Paths for Matchings
Proof
w.r.t. M
starting at u.
If P
is
also augmenting path w.r.t. M ().
Let u
that
is in P, and let e be the matching
edge from M
incident to u
from u to u
with P
1
.
P
1
P
1
is augmenting path in M ().
u
u
e
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 553/604
18 Augmenting Paths for Matchings
Proof
w.r.t. M
starting at u.
If P
is
also augmenting path w.r.t. M ().
Let u
that
is in P, and let e be the matching
edge from M
incident to u
from u to u
with P
1
.
P
1
P
1
is augmenting path in M ().
u
u
e
P
1
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 553/604
18 Augmenting Paths for Matchings
Proof
w.r.t. M
starting at u.
If P
is
also augmenting path w.r.t. M ().
Let u
that
is in P, and let e be the matching
edge from M
incident to u
from u to u
with P
1
.
P
1
P
1
is augmenting path in M ().
u
u
e
P
1
P
1
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 553/604
18 Augmenting Paths for Matchings
Proof
w.r.t. M
starting at u.
If P
is
also augmenting path w.r.t. M ().
Let u
that
is in P, and let e be the matching
edge from M
incident to u
from u to u
with P
1
.
P
1
P
1
is augmenting path in M ().
u
u
e
P
1
P
1
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 553/604
How to nd an augmenting path?
Construct an alternating tree.
u
y
even nodes
odd nodes
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 554/604
How to nd an augmenting path?
Construct an alternating tree.
u
y
x
even nodes
odd nodes
Case 1:
y is free vertex not
contained in T
you found
alternating path
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 554/604
How to nd an augmenting path?
Construct an alternating tree.
u
x
y
even nodes
odd nodes
Case 2:
y is matched vertex
not in T; then
mate[y] T
grow the tree
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 555/604
How to nd an augmenting path?
Construct an alternating tree.
u
x
y
even nodes
odd nodes
Case 3:
y is already contained
in T as an odd vertex
ignore successor y
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 556/604
How to nd an augmenting path?
Construct an alternating tree.
u
x
y
even nodes
odd nodes
Case 4:
y is already contained
in T as an even vertex
cant ignore y
does not happen in
bipartite graphs
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 557/604
Algorithm 50 BiMatch(G, match)
1: for x V do mate[x] 0;
2: r 0; free n;
3: while free 1 and r < n do
4: r r +1
5: if mate[r] = 0 then
6: for i = 1 to m do parent[i
] 0
7: Q ; Q. append(r); aug false;
8: while aug = false and Q do
9: x Q. dequeue();
10: for y A
x
do
11: if mate[y] = 0 then
12: augm(mate, parent, y);
13: aug true;
14: free free 1;
15: else
16: if parent[y] = 0 then
17: parent[y] x;
18: Q. enqueue(mate[y]);
graph G = (S S
, E)
S = 1, . . . , n
S
= 1
, . . . , n
] 0
7: Q ; Q. append(r); aug false;
8: while aug = false and Q do
9: x Q. dequeue();
10: for y A
x
do
11: if mate[y] = 0 then
12: augm(mate, parent, y);
13: aug true;
14: free free 1;
15: else
16: if parent[y] = 0 then
17: parent[y] x;
18: Q. enqueue(mate[y]);
start with an
empty matching
Algorithm 50 BiMatch(G, match)
1: for x V do mate[x] 0;
2: r 0; free n;
3: while free 1 and r < n do
4: r r +1
5: if mate[r] = 0 then
6: for i = 1 to m do parent[i
] 0
7: Q ; Q. append(r); aug false;
8: while aug = false and Q do
9: x Q. dequeue();
10: for y A
x
do
11: if mate[y] = 0 then
12: augm(mate, parent, y);
13: aug true;
14: free free 1;
15: else
16: if parent[y] = 0 then
17: parent[y] x;
18: Q. enqueue(mate[y]);
free: number of
unmatched nodes in
S
r: root of current tree
Algorithm 50 BiMatch(G, match)
1: for x V do mate[x] 0;
2: r 0; free n;
3: while free 1 and r < n do
4: r r +1
5: if mate[r] = 0 then
6: for i = 1 to m do parent[i
] 0
7: Q ; Q. append(r); aug false;
8: while aug = false and Q do
9: x Q. dequeue();
10: for y A
x
do
11: if mate[y] = 0 then
12: augm(mate, parent, y);
13: aug true;
14: free free 1;
15: else
16: if parent[y] = 0 then
17: parent[y] x;
18: Q. enqueue(mate[y]);
as long as there are
unmatched nodes and
we did not yet try to
grow from all nodes we
continue
Algorithm 50 BiMatch(G, match)
1: for x V do mate[x] 0;
2: r 0; free n;
3: while free 1 and r < n do
4: r r +1
5: if mate[r] = 0 then
6: for i = 1 to m do parent[i
] 0
7: Q ; Q. append(r); aug false;
8: while aug = false and Q do
9: x Q. dequeue();
10: for y A
x
do
11: if mate[y] = 0 then
12: augm(mate, parent, y);
13: aug true;
14: free free 1;
15: else
16: if parent[y] = 0 then
17: parent[y] x;
18: Q. enqueue(mate[y]);
r is the new node that
we grow from.
Algorithm 50 BiMatch(G, match)
1: for x V do mate[x] 0;
2: r 0; free n;
3: while free 1 and r < n do
4: r r +1
5: if mate[r] = 0 then
6: for i = 1 to m do parent[i
] 0
7: Q ; Q. append(r); aug false;
8: while aug = false and Q do
9: x Q. dequeue();
10: for y A
x
do
11: if mate[y] = 0 then
12: augm(mate, parent, y);
13: aug true;
14: free free 1;
15: else
16: if parent[y] = 0 then
17: parent[y] x;
18: Q. enqueue(mate[y]);
If r is free start tree
construction
Algorithm 50 BiMatch(G, match)
1: for x V do mate[x] 0;
2: r 0; free n;
3: while free 1 and r < n do
4: r r +1
5: if mate[r] = 0 then
6: for i = 1 to m do parent[i
] 0
7: Q ; Q. append(r); aug false;
8: while aug = false and Q do
9: x Q. dequeue();
10: for y A
x
do
11: if mate[y] = 0 then
12: augm(mate, parent, y);
13: aug true;
14: free free 1;
15: else
16: if parent[y] = 0 then
17: parent[y] x;
18: Q. enqueue(mate[y]);
Initialize an empty tree.
Note that only nodes i
] 0
7: Q ; Q. append(r); aug false;
8: while aug = false and Q do
9: x Q. dequeue();
10: for y A
x
do
11: if mate[y] = 0 then
12: augm(mate, parent, y);
13: aug true;
14: free free 1;
15: else
16: if parent[y] = 0 then
17: parent[y] x;
18: Q. enqueue(mate[y]);
Q is a queue (BFS!!!).
aug is a Boolean that
stores whether we
already found an
augmenting path.
Algorithm 50 BiMatch(G, match)
1: for x V do mate[x] 0;
2: r 0; free n;
3: while free 1 and r < n do
4: r r +1
5: if mate[r] = 0 then
6: for i = 1 to m do parent[i
] 0
7: Q ; Q. append(r); aug false;
8: while aug = false and Q do
9: x Q. dequeue();
10: for y A
x
do
11: if mate[y] = 0 then
12: augm(mate, parent, y);
13: aug true;
14: free free 1;
15: else
16: if parent[y] = 0 then
17: parent[y] x;
18: Q. enqueue(mate[y]);
as long as we did not
augment and there are
still unexamined leaves
continue...
Algorithm 50 BiMatch(G, match)
1: for x V do mate[x] 0;
2: r 0; free n;
3: while free 1 and r < n do
4: r r +1
5: if mate[r] = 0 then
6: for i = 1 to m do parent[i
] 0
7: Q ; Q. append(r); aug false;
8: while aug = false and Q do
9: x Q. dequeue();
10: for y A
x
do
11: if mate[y] = 0 then
12: augm(mate, parent, y);
13: aug true;
14: free free 1;
15: else
16: if parent[y] = 0 then
17: parent[y] x;
18: Q. enqueue(mate[y]);
take next unexamined
leaf
Algorithm 50 BiMatch(G, match)
1: for x V do mate[x] 0;
2: r 0; free n;
3: while free 1 and r < n do
4: r r +1
5: if mate[r] = 0 then
6: for i = 1 to m do parent[i
] 0
7: Q ; Q. append(r); aug false;
8: while aug = false and Q do
9: x Q. dequeue();
10: for y A
x
do
11: if mate[y] = 0 then
12: augm(mate, parent, y);
13: aug true;
14: free free 1;
15: else
16: if parent[y] = 0 then
17: parent[y] x;
18: Q. enqueue(mate[y]);
if x has unmatched
neighbour we found an
augmenting path (note
that y r because we
are in a bipartite graph)
Algorithm 50 BiMatch(G, match)
1: for x V do mate[x] 0;
2: r 0; free n;
3: while free 1 and r < n do
4: r r +1
5: if mate[r] = 0 then
6: for i = 1 to m do parent[i
] 0
7: Q ; Q. append(r); aug false;
8: while aug = false and Q do
9: x Q. dequeue();
10: for y A
x
do
11: if mate[y] = 0 then
12: augm(mate, parent, y);
13: aug true;
14: free free 1;
15: else
16: if parent[y] = 0 then
17: parent[y] x;
18: Q. enqueue(mate[y]);
do an augmentation...
Algorithm 50 BiMatch(G, match)
1: for x V do mate[x] 0;
2: r 0; free n;
3: while free 1 and r < n do
4: r r +1
5: if mate[r] = 0 then
6: for i = 1 to m do parent[i
] 0
7: Q ; Q. append(r); aug false;
8: while aug = false and Q do
9: x Q. dequeue();
10: for y A
x
do
11: if mate[y] = 0 then
12: augm(mate, parent, y);
13: aug true;
14: free free 1;
15: else
16: if parent[y] = 0 then
17: parent[y] x;
18: Q. enqueue(mate[y]);
setting aug = true
ensures that the tree
construction will not
continue
Algorithm 50 BiMatch(G, match)
1: for x V do mate[x] 0;
2: r 0; free n;
3: while free 1 and r < n do
4: r r +1
5: if mate[r] = 0 then
6: for i = 1 to m do parent[i
] 0
7: Q ; Q. append(r); aug false;
8: while aug = false and Q do
9: x Q. dequeue();
10: for y A
x
do
11: if mate[y] = 0 then
12: augm(mate, parent, y);
13: aug true;
14: free free 1;
15: else
16: if parent[y] = 0 then
17: parent[y] x;
18: Q. enqueue(mate[y]);
reduce number of free
nodes
Algorithm 50 BiMatch(G, match)
1: for x V do mate[x] 0;
2: r 0; free n;
3: while free 1 and r < n do
4: r r +1
5: if mate[r] = 0 then
6: for i = 1 to m do parent[i
] 0
7: Q ; Q. append(r); aug false;
8: while aug = false and Q do
9: x Q. dequeue();
10: for y A
x
do
11: if mate[y] = 0 then
12: augm(mate, parent, y);
13: aug true;
14: free free 1;
15: else
16: if parent[y] = 0 then
17: parent[y] x;
18: Q. enqueue(mate[y]);
if y is not in the tree yet
Algorithm 50 BiMatch(G, match)
1: for x V do mate[x] 0;
2: r 0; free n;
3: while free 1 and r < n do
4: r r +1
5: if mate[r] = 0 then
6: for i = 1 to m do parent[i
] 0
7: Q ; Q. append(r); aug false;
8: while aug = false and Q do
9: x Q. dequeue();
10: for y A
x
do
11: if mate[y] = 0 then
12: augm(mate, parent, y);
13: aug true;
14: free free 1;
15: else
16: if parent[y] = 0 then
17: parent[y] x;
18: Q. enqueue(mate[y]);
...put it into the tree
Algorithm 50 BiMatch(G, match)
1: for x V do mate[x] 0;
2: r 0; free n;
3: while free 1 and r < n do
4: r r +1
5: if mate[r] = 0 then
6: for i = 1 to m do parent[i
] 0
7: Q ; Q. append(r); aug false;
8: while aug = false and Q do
9: x Q. dequeue();
10: for y A
x
do
11: if mate[y] = 0 then
12: augm(mate, parent, y);
13: aug true;
14: free free 1;
15: else
16: if parent[y] = 0 then
17: parent[y] x;
18: Q. enqueue(mate[y]);
add its buddy to the set
of unexamined leaves
19 Weighted Bipartite Matching
Weighted Bipartite Matching/Assignment
assume that L = R = n
5
S
Halls Theorem
Proof:
Of course, the condition is necessary as otherwise not all
nodes in S could be matched to dierent neigbhours.
For the other direction we need to argue that the minimum
cut in the graph G
is at least L.
This gives R
S
(L
S
).
is at least L.
This gives R
S
(L
S
).
is at least L.
This gives R
S
(L
S
).
is at least L.
This gives R
S
(L
S
).
is at least L.
This gives R
S
(L
S
).
is at least L.
This gives R
S
(L
S
).
is at least L.
This gives R
S
(L
S
).
is
(u,v)M
w
(u,v)
=
(u,v)M
(x
u
+x
v
) =
v
x
v
.
(u,v)M
w
(u,v)
(u,v)M
(x
u
+x
v
)
v
x
v
.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 564/604
Algorithm Outline
What if you dont nd a perfect matching?
Then, Halls theorem guarantees you that there is a set S L,
with (S) < S, where denotes the neighbourhood w.r.t. the
subgraph H( x).
Idea: reweight such that:
+
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 566/604
Changing Node Weights
Increase node-weights in (S) by +, and decrease the
node-weights in S by .
+
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 566/604
Changing Node Weights
Increase node-weights in (S) by +, and decrease the
node-weights in S by .
+
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 566/604
Changing Node Weights
Increase node-weights in (S) by +, and decrease the
node-weights in S by .
+
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 566/604
Weighted Bipartite Matching
Edges not drawn have weight 0.
5
2
6
4
2
4
1
6
3
1
3
0
6
2
0
0
0
0
0
0
0
1
0
0
0
0
2
0
0
1
2
2
4
6
4
1
2
5
3
3
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 567/604
Weighted Bipartite Matching
Edges not drawn have weight 0.
5
2
6
4
2
4
1
6
3
1
3
0
6
2
0
0
0
0
0
0
0
1
0
0
0
0
2
0
0
1
2
2
4
6
4
1
2
5
3
3
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 567/604
Weighted Bipartite Matching
Edges not drawn have weight 0.
5
2
6
4
2
4
1
6
3
1
3
0
6
2
0
0
0
0
0
0
0
1
0
0
0
0
2
0
0
1
2
2
4
6
4
1
2
5
3
3
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 567/604
Weighted Bipartite Matching
Edges not drawn have weight 0.
5
2
6
4
2
4
1
6
3
1
3
0
6
2
0
0
0
0
0
0
0
1
0
0
0
0
2
0
0
1
2
2
4
6
4
1
2
5
3
3
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 567/604
Weighted Bipartite Matching
Edges not drawn have weight 0.
= 1
5
2
6
4
2
4
1
6
3
1
3
0
6
2
0
0
0
0
0
0
0
1
0
0
0
0
2
0
0
1
2
2
4
6
4
1
2
5
3
3
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 567/604
Weighted Bipartite Matching
Edges not drawn have weight 0.
5
2
6
4
2
4
1
6
3
1
3
0
6
2
0
0
0
0
0
0
0
1
0
0
0
0
2
0
0
1
2
2
4
6
4
1
2
5
3
3
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 567/604
Weighted Bipartite Matching
Edges not drawn have weight 0.
5
2
6
4
2
4
1
6
3
1
3
0
6
2
0
0
0
0
0
0
0
1
0
0
0
0
2
0
0
1
2
2
4
6
4
1
2
5
3
3
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 567/604
Weighted Bipartite Matching
Edges not drawn have weight 0.
= 1
5
2
6
4
2
4
1
6
3
1
3
0
6
2
0
0
0
0
0
0
0
1
0
0
0
0
2
0
0
1
2
2
4
6
4
1
2
5
3
3
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 567/604
Weighted Bipartite Matching
Edges not drawn have weight 0.
5
2
6
4
2
4
1
6
3
1
3
0
6
2
0
0
0
0
0
0
0
1
0
0
0
0
2
0
0
1
2
2
4
6
4
1
2
5
3
3
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 567/604
Weighted Bipartite Matching
Edges not drawn have weight 0.
5
2
6
4
2
4
1
6
3
1
3
0
6
2
0
0
0
0
0
0
0
1
0
0
0
0
2
0
0
1
2
2
4
6
4
1
2
5
3
3
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 567/604
Weighted Bipartite Matching
Edges not drawn have weight 0.
5
2
6
4
2
4
1
6
3
1
3
0
6
2
0
0
0
0
0
0
0
1
0
0
0
0
2
0
0
1
2
2
4
6
4
1
2
5
3
3
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 567/604
Analysis
How many iterations do we need?
The set of even vertices is on the left and the set of odd
vertices is on the right and contains all neighbours of even
nodes.
The set of even vertices is on the left and the set of odd
vertices is on the right and contains all neighbours of even
nodes.
The set of even vertices is on the left and the set of odd
vertices is on the right and contains all neighbours of even
nodes.
The set of even vertices is on the left and the set of odd
vertices is on the right and contains all neighbours of even
nodes.
there exist
M
there exist
M
there exist
M
there exist
M
there exist
M
there exist
M
Let P
1
, . . . , P
k
be a maximal collection of vertex-disjoint,
shortest augmenting paths w.r.t. M (let = P
i
).
= M (P
1
P
k
) = M P
1
P
k
.
.
Lemma 5
The set A = M (M
P) = (P
1
P
k
) P contains at least
(k +1) edges.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 575/604
Analysis
Let P
1
, . . . , P
k
be a maximal collection of vertex-disjoint,
shortest augmenting paths w.r.t. M (let = P
i
).
= M (P
1
P
k
) = M P
1
P
k
.
.
Lemma 5
The set A = M (M
P) = (P
1
P
k
) P contains at least
(k +1) edges.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 575/604
Analysis
Let P
1
, . . . , P
k
be a maximal collection of vertex-disjoint,
shortest augmenting paths w.r.t. M (let = P
i
).
= M (P
1
P
k
) = M P
1
P
k
.
.
Lemma 5
The set A = M (M
P) = (P
1
P
k
) P contains at least
(k +1) edges.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 575/604
Analysis
Let P
1
, . . . , P
k
be a maximal collection of vertex-disjoint,
shortest augmenting paths w.r.t. M (let = P
i
).
= M (P
1
P
k
) = M P
1
P
k
.
.
Lemma 5
The set A = M (M
P) = (P
1
P
k
) P contains at least
(k +1) edges.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 575/604
Analysis
Proof.
P.
= M +k +1.
P.
= M +k +1.
P.
= M +k +1.
Hence, A k +P 1.
Hence, A k +P 1.
Hence, A k +P 1.
Hence, A k +P 1.
Hence, A k +P 1.
Hence, A k +P 1.
contains
M
contains
M
V phases.
Proof.
After iteration |
V] +1
V.
V +1)
V
additional augmentations.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 579/604
Analysis
Lemma 7
The Hopcroft-Karp algorithm requires at most 2
V phases.
Proof.
After iteration |
V] +1
V.
V +1)
V
additional augmentations.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 579/604
Analysis
Lemma 8
One phase of the Hopcroft-Karp algorithm can be implemented
in time O(m).
Any such path must visit the layers of the BFS-tree from left
to right.
= G/B, which is
obtained from G by contracting the blossom B.
= G/B, which is
obtained from G by contracting the blossom B.
= G/B, which is
obtained from G by contracting the blossom B.
connecting u to
b.
.
w
x y
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 590/604
Shrinking Blossoms
connecting u to
b.
.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 590/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8 9
10 11 12 13
14
15 16 17
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8 9
10 11 12 13
14
15 16 17
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8 9
10 11 12 13
14
15 16 17
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8 9
10 11 12 13
14
15 16 17
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8 9
10 11 12 13
14
15 16 17
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8 9
10 11 12 13
14
15 16 17
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8 9
10 11 12 13
14
15 16 17
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8 9
10 11 12 13
14
15 16 17
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8 9
10 11 12 13
14
15 16 17
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8 9
10 11 12 13
14
15 16 17
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8 9
10 11 12 13
14
15 16 17
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8
10 11
14
15
1
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8
10 11
14
15
1
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8
10 11
14
15
1
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8
10 11
14
15
1
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8
10 11
14
15
1
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8
10 11
14
15
1
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
5 6
14
2
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
5 6
14
2
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
5 6
14
2
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8
10 11
14
15
1
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8
10 11
14
15
1
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8 9
10 11 12 13
14
15 16 17
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8 9
10 11 12 13
14
15 16 17
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Example: Blossom Algorithm
0 1 2 3
4 5 6
7
8 9
10 11 12 13
14
15 16 17
dierent
choices
dierent
choices
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 591/604
Assume that we have contracted a blossom B w.r.t. a matching
M whose base is w. We created graph G
= G/B with
pseudonode b. Let M
then G
contains an augmenting path starting at r w.r.t. matching M.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 592/604
Assume that we have contracted a blossom B w.r.t. a matching
M whose base is w. We created graph G
= G/B with
pseudonode b. Let M
then G
contains an augmenting path starting at r w.r.t. matching M.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 592/604
Proof.
If p
P
1
(i, w) P
2
(k, ) P
3
is an alternating path.
If k = w then P
1
(i, w) (w, ) P
3
is an alternating path.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 594/604
Proof.
Case 2: empty stem
The path r P
2
(k, ) P
3
is an alternating path.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 595/604
Proof.
Case 2: empty stem
The path r P
2
(k, ) P
3
is an alternating path.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 595/604
Proof.
Case 2: empty stem
The path r P
2
(k, ) P
3
is an alternating path.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 595/604
Proof.
Case 2: empty stem
The path r P
2
(k, ) P
3
is an alternating path.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 595/604
Lemma 11
If G contains an augmenting path P from r to q w.r.t. matching
M then G
.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 596/604
Proof.
+
the blossom has an empty stem. Case 1 applies.
G
+
. It must also have an
augmenting path w.r.t. M
+
the blossom has an empty stem. Case 1 applies.
G
+
. It must also have an
augmenting path w.r.t. M
+
the blossom has an empty stem. Case 1 applies.
G
+
. It must also have an
augmenting path w.r.t. M
+
the blossom has an empty stem. Case 1 applies.
G
+
. It must also have an
augmenting path w.r.t. M
+
the blossom has an empty stem. Case 1 applies.
G
+
. It must also have an
augmenting path w.r.t. M
+
the blossom has an empty stem. Case 1 applies.
G
+
. It must also have an
augmenting path w.r.t. M
+
the blossom has an empty stem. Case 1 applies.
G
+
. It must also have an
augmenting path w.r.t. M
+
the blossom has an empty stem. Case 1 applies.
G
+
. It must also have an
augmenting path w.r.t. M