0% found this document useful (0 votes)
66 views266 pages

Part Matchings

M [?] E is a matching if each node appears in at most one edge in M. A matching is perfect if it is of cardinality M = V / 2.

Uploaded by

hisuin
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views266 pages

Part Matchings

M [?] E is a matching if each node appears in at most one edge in M. A matching is perfect if it is of cardinality M = V / 2.

Uploaded by

hisuin
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 266

Part V

Matchings
EADS
Ernst Mayr, Harald Rcke 540/604
Matching

Input: undirected graph G = (V, E).

M E is a matching if each node appears in at most one


edge in M.

Maximum Matching: nd a matching of maximum


cardinality
Bipartite Matching

Input: undirected, bipartite graph G = (L R, E).

M E is a matching if each node appears in at most one


edge in M.

Maximum Matching: nd a matching of maximum


cardinality
1
2
3
4
5
L R

5
EADS 16 Denition
Ernst Mayr, Harald Rcke 542/604
Bipartite Matching

Input: undirected, bipartite graph G = (L R, E).

M E is a matching if each node appears in at most one


edge in M.

Maximum Matching: nd a matching of maximum


cardinality
1
2
3
4
5
L R

5
EADS 16 Denition
Ernst Mayr, Harald Rcke 543/604
Bipartite Matching

A matching M is perfect if it is of cardinality M = V/2.

For a bipartite graph G = (L R, E) this means


M = L = R = n.
1
2
3
4
5
L R

5
EADS 16 Denition
Ernst Mayr, Harald Rcke 544/604
17 Bipartite Matching via Flows

Input: undirected, bipartite graph G = (L R s, t, E

).

Direct all edges from L to R.

Add source s and connect it to all nodes on the left.

Add t and connect all nodes on the right to t.

All edges have unit capacity.


s t
1
2
3
4
5
L R

5
Proof
Max cardinality matching in G value of maxow in G

Given a maximum matching M of cardinality k.

Consider ow f that sends one unit along each of k paths.

f is a ow and has cardinality k.


s t
1
2
3
4
5
L R
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

Given a maximum matching M of cardinality k.

Consider ow f that sends one unit along each of k paths.

f is a ow and has cardinality k.


s t
1
2
3
4
5
L R
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

Given a maximum matching M of cardinality k.

Consider ow f that sends one unit along each of k paths.

f is a ow and has cardinality k.


s t
1
2
3
4
5
L R
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

Given a maximum matching M of cardinality k.

Consider ow f that sends one unit along each of k paths.

f is a ow and has cardinality k.


s t
1
2
3
4
5
L R
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

Integrality theorem k integral; we can assume f is 0/1.

Consider M= set of edges from L to R with f(e) = 1.

Each node in L and R participates in at most one edge in M.

M = k, as the ow must use at least k middle edges.


s t
1
2
3
4
5
L R
G

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

Integrality theorem k integral; we can assume f is 0/1.

Consider M= set of edges from L to R with f(e) = 1.

Each node in L and R participates in at most one edge in M.

M = k, as the ow must use at least k middle edges.


s t
1
2
3
4
5
L R
G

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

Integrality theorem k integral; we can assume f is 0/1.

Consider M= set of edges from L to R with f(e) = 1.

Each node in L and R participates in at most one edge in M.

M = k, as the ow must use at least k middle edges.


s t
1
2
3
4
5
L R
G

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?

Generic augmenting path: O(mval(f

)) = O(mn).

Capacity scaling: O(m


2
logC) = O(m
2
).
EADS 17 Bipartite Matching via Flows
Ernst Mayr, Harald Rcke 548/604
18 Augmenting Paths for Matchings
Denitions.

Given a matching M in a graph G, a vertex that is not


incident to any edge of M is called a free vertex w. r. .t. M.

For a matching M a path P in G is called an alternating path


if edges in M alternate with edges not in M.

An alternating path is called an augmenting path for


matching M if it ends at distinct free vertices.
Theorem 1
A matching M is a maximum matching if and only if there is no
augmenting path w. r. t. M.
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 549/604
18 Augmenting Paths for Matchings
Denitions.

Given a matching M in a graph G, a vertex that is not


incident to any edge of M is called a free vertex w. r. .t. M.

For a matching M a path P in G is called an alternating path


if edges in M alternate with edges not in M.

An alternating path is called an augmenting path for


matching M if it ends at distinct free vertices.
Theorem 1
A matching M is a maximum matching if and only if there is no
augmenting path w. r. t. M.
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 549/604
18 Augmenting Paths for Matchings
Denitions.

Given a matching M in a graph G, a vertex that is not


incident to any edge of M is called a free vertex w. r. .t. M.

For a matching M a path P in G is called an alternating path


if edges in M alternate with edges not in M.

An alternating path is called an augmenting path for


matching M if it ends at distinct free vertices.
Theorem 1
A matching M is a maximum matching if and only if there is no
augmenting path w. r. t. M.
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 549/604
18 Augmenting Paths for Matchings
Denitions.

Given a matching M in a graph G, a vertex that is not


incident to any edge of M is called a free vertex w. r. .t. M.

For a matching M a path P in G is called an alternating path


if edges in M alternate with edges not in M.

An alternating path is called an augmenting path for


matching M if it ends at distinct free vertices.
Theorem 1
A matching M is a maximum matching if and only if there is no
augmenting path w. r. t. M.
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 549/604
Augmenting Paths in Action
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 550/604
Augmenting Paths in Action
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 550/604
Augmenting Paths in Action
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 550/604
Augmenting Paths in Action
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 550/604
Augmenting Paths in Action
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 550/604
Augmenting Paths in Action
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14
EADS 18 Augmenting Paths for Matchings
Ernst Mayr, Harald Rcke 550/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

= M P with larger cardinality.


Suppose there is a matching M

with larger cardinality.


Consider the graph H with edge-set M

M (i.e., only edges


that are in either M or M

but not in both).


Each vertex can be incident to at most two edges (one from
M and one from M

). Hence, the connected components are


alternating cycles or alternating path.
As M

> M there is one connected component that is a


path P for which both endpoints are incident to edges from
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

= M P with larger cardinality.


Suppose there is a matching M

with larger cardinality.


Consider the graph H with edge-set M

M (i.e., only edges


that are in either M or M

but not in both).


Each vertex can be incident to at most two edges (one from
M and one from M

). Hence, the connected components are


alternating cycles or alternating path.
As M

> M there is one connected component that is a


path P for which both endpoints are incident to edges from
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

= M P with larger cardinality.


Suppose there is a matching M

with larger cardinality.


Consider the graph H with edge-set M

M (i.e., only edges


that are in either M or M

but not in both).


Each vertex can be incident to at most two edges (one from
M and one from M

). Hence, the connected components are


alternating cycles or alternating path.
As M

> M there is one connected component that is a


path P for which both endpoints are incident to edges from
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

= M P with larger cardinality.


Suppose there is a matching M

with larger cardinality.


Consider the graph H with edge-set M

M (i.e., only edges


that are in either M or M

but not in both).


Each vertex can be incident to at most two edges (one from
M and one from M

). Hence, the connected components are


alternating cycles or alternating path.
As M

> M there is one connected component that is a


path P for which both endpoints are incident to edges from
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

= M P denote the matching resulting from augmenting


M with P. If there was no augmenting path starting at u in M
then there is no augmenting path starting at u in 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

= M P denote the matching resulting from augmenting


M with P. If there was no augmenting path starting at u in M
then there is no augmenting path starting at u in 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

Assume there is an augmenting


path P

w.r.t. M

starting at u.

If P

and P are node-disjoint, P

is
also augmenting path w.r.t. M ().

Let u

be the rst node on P

that
is in P, and let e be the matching
edge from M

incident to u

splits P into two parts one of


which does not contain e. Call this
part P
1
. Denote the sub-path of P

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

Assume there is an augmenting


path P

w.r.t. M

starting at u.

If P

and P are node-disjoint, P

is
also augmenting path w.r.t. M ().

Let u

be the rst node on P

that
is in P, and let e be the matching
edge from M

incident to u

splits P into two parts one of


which does not contain e. Call this
part P
1
. Denote the sub-path of P

from u to u

with P

1
.

P
1
P

1
is augmenting path in M ().
u
P

EADS 18 Augmenting Paths for Matchings


Ernst Mayr, Harald Rcke 553/604
18 Augmenting Paths for Matchings
Proof

Assume there is an augmenting


path P

w.r.t. M

starting at u.

If P

and P are node-disjoint, P

is
also augmenting path w.r.t. M ().

Let u

be the rst node on P

that
is in P, and let e be the matching
edge from M

incident to u

splits P into two parts one of


which does not contain e. Call this
part P
1
. Denote the sub-path of P

from u to u

with P

1
.

P
1
P

1
is augmenting path in M ().
u
P

EADS 18 Augmenting Paths for Matchings


Ernst Mayr, Harald Rcke 553/604
18 Augmenting Paths for Matchings
Proof

Assume there is an augmenting


path P

w.r.t. M

starting at u.

If P

and P are node-disjoint, P

is
also augmenting path w.r.t. M ().

Let u

be the rst node on P

that
is in P, and let e be the matching
edge from M

incident to u

splits P into two parts one of


which does not contain e. Call this
part P
1
. Denote the sub-path of P

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

Assume there is an augmenting


path P

w.r.t. M

starting at u.

If P

and P are node-disjoint, P

is
also augmenting path w.r.t. M ().

Let u

be the rst node on P

that
is in P, and let e be the matching
edge from M

incident to u

splits P into two parts one of


which does not contain e. Call this
part P
1
. Denote the sub-path of P

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

Assume there is an augmenting


path P

w.r.t. M

starting at u.

If P

and P are node-disjoint, P

is
also augmenting path w.r.t. M ().

Let u

be the rst node on P

that
is in P, and let e be the matching
edge from M

incident to u

splits P into two parts one of


which does not contain e. Call this
part P
1
. Denote the sub-path of P

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

Assume there is an augmenting


path P

w.r.t. M

starting at u.

If P

and P are node-disjoint, P

is
also augmenting path w.r.t. M ().

Let u

be the rst node on P

that
is in P, and let e be the matching
edge from M

incident to u

splits P into two parts one of


which does not contain e. Call this
part P
1
. Denote the sub-path of P

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

Assume there is an augmenting


path P

w.r.t. M

starting at u.

If P

and P are node-disjoint, P

is
also augmenting path w.r.t. M ().

Let u

be the rst node on P

that
is in P, and let e be the matching
edge from M

incident to u

splits P into two parts one of


which does not contain e. Call this
part P
1
. Denote the sub-path of P

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

Assume there is an augmenting


path P

w.r.t. M

starting at u.

If P

and P are node-disjoint, P

is
also augmenting path w.r.t. M ().

Let u

be the rst node on P

that
is in P, and let e be the matching
edge from M

incident to u

splits P into two parts one of


which does not contain e. Call this
part P
1
. Denote the sub-path of P

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

Assume there is an augmenting


path P

w.r.t. M

starting at u.

If P

and P are node-disjoint, P

is
also augmenting path w.r.t. M ().

Let u

be the rst node on P

that
is in P, and let e be the matching
edge from M

incident to u

splits P into two parts one of


which does not contain e. Call this
part P
1
. Denote the sub-path of P

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

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]);
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

have parent pointers.


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]);
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

Input: undirected, bipartite graph G = L R, E.

an edge e = (, r) has weight w


e
0

nd a matching of maximum weight, where the weight of a


matching is the sum of the weights of its edges
Simplifying Assumptions (wlog [why?]):

assume that L = R = n

assume that there is an edge between every pair of nodes


(, r) V V
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 559/604
Weighted Bipartite Matching
Theorem 3 (Halls Theorem)
A bipartite graph G = (L R, E) has a perfect matching if and
only if for all sets S L, (S) S, where (S) denotes the set
of nodes in R that have a neighbour in S.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 560/604
19 Weighted Bipartite Matching
s t
1
2
3
4
5
L R

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.

Let S denote a minimum cut and let L


S
= L S and
R
S
= R S denote the portion of S inside L and R,
respectively.

Clearly, all neighbours of nodes in L


S
have to be in S, as
otherwise we would cut an edge of innite capacity.

This gives R
S
(L
S
).

The size of the cut is L L


S
+R
S
.

Using the fact that (L


S
) L
S
gives that this is at least L.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 562/604
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.

Let S denote a minimum cut and let L


S
= L S and
R
S
= R S denote the portion of S inside L and R,
respectively.

Clearly, all neighbours of nodes in L


S
have to be in S, as
otherwise we would cut an edge of innite capacity.

This gives R
S
(L
S
).

The size of the cut is L L


S
+R
S
.

Using the fact that (L


S
) L
S
gives that this is at least L.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 562/604
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.

Let S denote a minimum cut and let L


S
= L S and
R
S
= R S denote the portion of S inside L and R,
respectively.

Clearly, all neighbours of nodes in L


S
have to be in S, as
otherwise we would cut an edge of innite capacity.

This gives R
S
(L
S
).

The size of the cut is L L


S
+R
S
.

Using the fact that (L


S
) L
S
gives that this is at least L.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 562/604
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.

Let S denote a minimum cut and let L


S
= L S and
R
S
= R S denote the portion of S inside L and R,
respectively.

Clearly, all neighbours of nodes in L


S
have to be in S, as
otherwise we would cut an edge of innite capacity.

This gives R
S
(L
S
).

The size of the cut is L L


S
+R
S
.

Using the fact that (L


S
) L
S
gives that this is at least L.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 562/604
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.

Let S denote a minimum cut and let L


S
= L S and
R
S
= R S denote the portion of S inside L and R,
respectively.

Clearly, all neighbours of nodes in L


S
have to be in S, as
otherwise we would cut an edge of innite capacity.

This gives R
S
(L
S
).

The size of the cut is L L


S
+R
S
.

Using the fact that (L


S
) L
S
gives that this is at least L.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 562/604
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.

Let S denote a minimum cut and let L


S
= L S and
R
S
= R S denote the portion of S inside L and R,
respectively.

Clearly, all neighbours of nodes in L


S
have to be in S, as
otherwise we would cut an edge of innite capacity.

This gives R
S
(L
S
).

The size of the cut is L L


S
+R
S
.

Using the fact that (L


S
) L
S
gives that this is at least L.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 562/604
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.

Let S denote a minimum cut and let L


S
= L S and
R
S
= R S denote the portion of S inside L and R,
respectively.

Clearly, all neighbours of nodes in L


S
have to be in S, as
otherwise we would cut an edge of innite capacity.

This gives R
S
(L
S
).

The size of the cut is L L


S
+R
S
.

Using the fact that (L


S
) L
S
gives that this is at least L.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 562/604
Algorithm Outline
Idea:
We introduce a node weighting x. Let for a node v V, x
v
0
denote the weight of node v.

Suppose that the node weights dominate the edge-weights


in the following sense:
x
u
+x
v
w
e
for every edge e = (u, v).

Let H( x) denote the subgraph of G that only contains


edges that are tight w.r.t. the node weighting x, i.e. edges
e = (u, v) for which w
e
= x
u
+x
v
.

Try to compute a perfect matching in the subgraph H( x). If


you are successful you found an optimal matching.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 563/604
Algorithm Outline
Idea:
We introduce a node weighting x. Let for a node v V, x
v
0
denote the weight of node v.

Suppose that the node weights dominate the edge-weights


in the following sense:
x
u
+x
v
w
e
for every edge e = (u, v).

Let H( x) denote the subgraph of G that only contains


edges that are tight w.r.t. the node weighting x, i.e. edges
e = (u, v) for which w
e
= x
u
+x
v
.

Try to compute a perfect matching in the subgraph H( x). If


you are successful you found an optimal matching.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 563/604
Algorithm Outline
Idea:
We introduce a node weighting x. Let for a node v V, x
v
0
denote the weight of node v.

Suppose that the node weights dominate the edge-weights


in the following sense:
x
u
+x
v
w
e
for every edge e = (u, v).

Let H( x) denote the subgraph of G that only contains


edges that are tight w.r.t. the node weighting x, i.e. edges
e = (u, v) for which w
e
= x
u
+x
v
.

Try to compute a perfect matching in the subgraph H( x). If


you are successful you found an optimal matching.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 563/604
Algorithm Outline
Idea:
We introduce a node weighting x. Let for a node v V, x
v
0
denote the weight of node v.

Suppose that the node weights dominate the edge-weights


in the following sense:
x
u
+x
v
w
e
for every edge e = (u, v).

Let H( x) denote the subgraph of G that only contains


edges that are tight w.r.t. the node weighting x, i.e. edges
e = (u, v) for which w
e
= x
u
+x
v
.

Try to compute a perfect matching in the subgraph H( x). If


you are successful you found an optimal matching.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 563/604
Algorithm Outline
Reason:

The weight of your matching M

is

(u,v)M

w
(u,v)
=

(u,v)M

(x
u
+x
v
) =

v
x
v
.

Any other matching M has

(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:

the total weight assigned to nodes decreases

the weight function still dominates the edge-weights


If we can do this we have an algorithm that terminates with an
optimal solution (we analyze the running time later).
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 565/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:

the total weight assigned to nodes decreases

the weight function still dominates the edge-weights


If we can do this we have an algorithm that terminates with an
optimal solution (we analyze the running time later).
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 565/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:

the total weight assigned to nodes decreases

the weight function still dominates the edge-weights


If we can do this we have an algorithm that terminates with an
optimal solution (we analyze the running time later).
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 565/604
Changing Node Weights
Increase node-weights in (S) by +, and decrease the
node-weights in S by .

Total node-weight decreases.

Only edges from S to R (S)


decrease in their weight.

Since, none of these edges is


tight (otw. the edge would be
contained in H( x), and hence
would go between S and (S))
we can do this decrement for
small enough > 0 until a new
edge gets tight.
L R
S
(S)

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

Total node-weight decreases.

Only edges from S to R (S)


decrease in their weight.

Since, none of these edges is


tight (otw. the edge would be
contained in H( x), and hence
would go between S and (S))
we can do this decrement for
small enough > 0 until a new
edge gets tight.
L R
S
(S)

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

Total node-weight decreases.

Only edges from S to R (S)


decrease in their weight.

Since, none of these edges is


tight (otw. the edge would be
contained in H( x), and hence
would go between S and (S))
we can do this decrement for
small enough > 0 until a new
edge gets tight.
L R
S
(S)

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

Total node-weight decreases.

Only edges from S to R (S)


decrease in their weight.

Since, none of these edges is


tight (otw. the edge would be
contained in H( x), and hence
would go between S and (S))
we can do this decrement for
small enough > 0 until a new
edge gets tight.
L R
S
(S)

+
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?

One reweighting step increases the number of edges out of


S by at least one.

Assume that we have a maximum matching that saturates


the set (S), in the sense that every node in (S) is matched
to a node in S (we will show that we can always nd S and a
matching such that this holds).

This matching is still contained in the new graph, because


all its edges either go between (S) and S or between L S
and R (S).

Hence, reweighting does not decrease the size of a


maximum matching in the tight sub-graph.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 568/604
Analysis
How many iterations do we need?

One reweighting step increases the number of edges out of


S by at least one.

Assume that we have a maximum matching that saturates


the set (S), in the sense that every node in (S) is matched
to a node in S (we will show that we can always nd S and a
matching such that this holds).

This matching is still contained in the new graph, because


all its edges either go between (S) and S or between L S
and R (S).

Hence, reweighting does not decrease the size of a


maximum matching in the tight sub-graph.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 568/604
Analysis
How many iterations do we need?

One reweighting step increases the number of edges out of


S by at least one.

Assume that we have a maximum matching that saturates


the set (S), in the sense that every node in (S) is matched
to a node in S (we will show that we can always nd S and a
matching such that this holds).

This matching is still contained in the new graph, because


all its edges either go between (S) and S or between L S
and R (S).

Hence, reweighting does not decrease the size of a


maximum matching in the tight sub-graph.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 568/604
Analysis
How many iterations do we need?

One reweighting step increases the number of edges out of


S by at least one.

Assume that we have a maximum matching that saturates


the set (S), in the sense that every node in (S) is matched
to a node in S (we will show that we can always nd S and a
matching such that this holds).

This matching is still contained in the new graph, because


all its edges either go between (S) and S or between L S
and R (S).

Hence, reweighting does not decrease the size of a


maximum matching in the tight sub-graph.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 568/604
Analysis

We will show that after at most n reweighting steps the size


of the maximum matching can be increased by nding an
augmenting path.

This gives a polynomial running time.


EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 569/604
How to nd an augmenting path?
Construct an alternating tree.
u
y
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 570/604
How to nd an augmenting path?
Construct an alternating tree.
u
y
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 570/604
Analysis
How do we nd S?

Start on the left and compute an alternating tree, starting at


any free node u.

If this construction stops, there is no perfect matching in


the tight subgraph (because for a perfect matching we need
to nd an augmenting path starting at u).

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.

All odd vertices are matched to even vertices. Furthermore,


the even vertices additionally contain the free vertex u.
Hence, V
odd
= (V
even
) < V
even
, and all odd vertices are
saturated in the current matching.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 571/604
Analysis
How do we nd S?

Start on the left and compute an alternating tree, starting at


any free node u.

If this construction stops, there is no perfect matching in


the tight subgraph (because for a perfect matching we need
to nd an augmenting path starting at u).

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.

All odd vertices are matched to even vertices. Furthermore,


the even vertices additionally contain the free vertex u.
Hence, V
odd
= (V
even
) < V
even
, and all odd vertices are
saturated in the current matching.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 571/604
Analysis
How do we nd S?

Start on the left and compute an alternating tree, starting at


any free node u.

If this construction stops, there is no perfect matching in


the tight subgraph (because for a perfect matching we need
to nd an augmenting path starting at u).

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.

All odd vertices are matched to even vertices. Furthermore,


the even vertices additionally contain the free vertex u.
Hence, V
odd
= (V
even
) < V
even
, and all odd vertices are
saturated in the current matching.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 571/604
Analysis
How do we nd S?

Start on the left and compute an alternating tree, starting at


any free node u.

If this construction stops, there is no perfect matching in


the tight subgraph (because for a perfect matching we need
to nd an augmenting path starting at u).

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.

All odd vertices are matched to even vertices. Furthermore,


the even vertices additionally contain the free vertex u.
Hence, V
odd
= (V
even
) < V
even
, and all odd vertices are
saturated in the current matching.
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 571/604
Analysis

The current matching does not have any edges from V


odd
to
outside of L \ V
even
(edges that may possibly be deleted by
changing weights).

After changing weights, there is at least one more edge


connecting V
even
to a node outside of V
odd
. After at most n
reweights we can do an augmentation.

A reweighting can be trivially performed in time O(n


2
)
(keeping track of the tight edges).

An augmentation takes at most O(n) time.

In total we otain a running time of O(n


4
).

A more careful implementation of the algorithm obtains a


running time of O(n
3
).
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 572/604
Analysis

The current matching does not have any edges from V


odd
to
outside of L \ V
even
(edges that may possibly be deleted by
changing weights).

After changing weights, there is at least one more edge


connecting V
even
to a node outside of V
odd
. After at most n
reweights we can do an augmentation.

A reweighting can be trivially performed in time O(n


2
)
(keeping track of the tight edges).

An augmentation takes at most O(n) time.

In total we otain a running time of O(n


4
).

A more careful implementation of the algorithm obtains a


running time of O(n
3
).
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 572/604
Analysis

The current matching does not have any edges from V


odd
to
outside of L \ V
even
(edges that may possibly be deleted by
changing weights).

After changing weights, there is at least one more edge


connecting V
even
to a node outside of V
odd
. After at most n
reweights we can do an augmentation.

A reweighting can be trivially performed in time O(n


2
)
(keeping track of the tight edges).

An augmentation takes at most O(n) time.

In total we otain a running time of O(n


4
).

A more careful implementation of the algorithm obtains a


running time of O(n
3
).
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 572/604
Analysis

The current matching does not have any edges from V


odd
to
outside of L \ V
even
(edges that may possibly be deleted by
changing weights).

After changing weights, there is at least one more edge


connecting V
even
to a node outside of V
odd
. After at most n
reweights we can do an augmentation.

A reweighting can be trivially performed in time O(n


2
)
(keeping track of the tight edges).

An augmentation takes at most O(n) time.

In total we otain a running time of O(n


4
).

A more careful implementation of the algorithm obtains a


running time of O(n
3
).
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 572/604
Analysis

The current matching does not have any edges from V


odd
to
outside of L \ V
even
(edges that may possibly be deleted by
changing weights).

After changing weights, there is at least one more edge


connecting V
even
to a node outside of V
odd
. After at most n
reweights we can do an augmentation.

A reweighting can be trivially performed in time O(n


2
)
(keeping track of the tight edges).

An augmentation takes at most O(n) time.

In total we otain a running time of O(n


4
).

A more careful implementation of the algorithm obtains a


running time of O(n
3
).
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 572/604
Analysis

The current matching does not have any edges from V


odd
to
outside of L \ V
even
(edges that may possibly be deleted by
changing weights).

After changing weights, there is at least one more edge


connecting V
even
to a node outside of V
odd
. After at most n
reweights we can do an augmentation.

A reweighting can be trivially performed in time O(n


2
)
(keeping track of the tight edges).

An augmentation takes at most O(n) time.

In total we otain a running time of O(n


4
).

A more careful implementation of the algorithm obtains a


running time of O(n
3
).
EADS 19 Weighted Bipartite Matching
Ernst Mayr, Harald Rcke 572/604
A Fast Matching Algorithm
Algorithm 50 Bimatch-Hopcroft-Karp(G)
1: M
2: repeat
3: let 1 = P
1
, . . . , P
k
be maximal set of
4: vertex-disjoint, shortest augmenting path w.r.t. M.
5: M M (P
1
P
k
)
6: until 1 =
7: return M
We call one iteration of the repeat-loop a phase of the algorithm.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 573/604
Analysis
Lemma 4
Given a matching M and a maximal matching M

there exist
M

M vertex-disjoint augmenting path w.r.t. M.


Proof:

Similar to the proof that a matching is optimal i it does not


contain an augmenting paths.

Consider the graph G = (V, M M

), and mark edges in


this graph blue if they are in M and red if they are in M

The connected components of G are cycles and paths.

The graph contains k = M

M more red edges than


blue edges.

Hence, there are at least k components that form a path


starting and ending with a blue edge. These are
augmenting paths w.r.t. M.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 574/604
Analysis
Lemma 4
Given a matching M and a maximal matching M

there exist
M

M vertex-disjoint augmenting path w.r.t. M.


Proof:

Similar to the proof that a matching is optimal i it does not


contain an augmenting paths.

Consider the graph G = (V, M M

), and mark edges in


this graph blue if they are in M and red if they are in M

The connected components of G are cycles and paths.

The graph contains k = M

M more red edges than


blue edges.

Hence, there are at least k components that form a path


starting and ending with a blue edge. These are
augmenting paths w.r.t. M.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 574/604
Analysis
Lemma 4
Given a matching M and a maximal matching M

there exist
M

M vertex-disjoint augmenting path w.r.t. M.


Proof:

Similar to the proof that a matching is optimal i it does not


contain an augmenting paths.

Consider the graph G = (V, M M

), and mark edges in


this graph blue if they are in M and red if they are in M

The connected components of G are cycles and paths.

The graph contains k = M

M more red edges than


blue edges.

Hence, there are at least k components that form a path


starting and ending with a blue edge. These are
augmenting paths w.r.t. M.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 574/604
Analysis
Lemma 4
Given a matching M and a maximal matching M

there exist
M

M vertex-disjoint augmenting path w.r.t. M.


Proof:

Similar to the proof that a matching is optimal i it does not


contain an augmenting paths.

Consider the graph G = (V, M M

), and mark edges in


this graph blue if they are in M and red if they are in M

The connected components of G are cycles and paths.

The graph contains k = M

M more red edges than


blue edges.

Hence, there are at least k components that form a path


starting and ending with a blue edge. These are
augmenting paths w.r.t. M.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 574/604
Analysis
Lemma 4
Given a matching M and a maximal matching M

there exist
M

M vertex-disjoint augmenting path w.r.t. M.


Proof:

Similar to the proof that a matching is optimal i it does not


contain an augmenting paths.

Consider the graph G = (V, M M

), and mark edges in


this graph blue if they are in M and red if they are in M

The connected components of G are cycles and paths.

The graph contains k = M

M more red edges than


blue edges.

Hence, there are at least k components that form a path


starting and ending with a blue edge. These are
augmenting paths w.r.t. M.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 574/604
Analysis
Lemma 4
Given a matching M and a maximal matching M

there exist
M

M vertex-disjoint augmenting path w.r.t. M.


Proof:

Similar to the proof that a matching is optimal i it does not


contain an augmenting paths.

Consider the graph G = (V, M M

), and mark edges in


this graph blue if they are in M and red if they are in M

The connected components of G are cycles and paths.

The graph contains k = M

M more red edges than


blue edges.

Hence, there are at least k components that form a path


starting and ending with a blue edge. These are
augmenting paths w.r.t. M.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 574/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
.

Let P be an augmenting path in M

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

Let P be an augmenting path in M

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

Let P be an augmenting path in M

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

Let P be an augmenting path in M

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

The set describes exactly the symmetric dierence between


matchings M and M

P.

Hence, the set contains at least k +1 vertex-disjoint


augmenting paths w.r.t. M as M

= M +k +1.

Each of these paths is of length at least .


EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 576/604
Analysis
Proof.

The set describes exactly the symmetric dierence between


matchings M and M

P.

Hence, the set contains at least k +1 vertex-disjoint


augmenting paths w.r.t. M as M

= M +k +1.

Each of these paths is of length at least .


EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 576/604
Analysis
Proof.

The set describes exactly the symmetric dierence between


matchings M and M

P.

Hence, the set contains at least k +1 vertex-disjoint


augmenting paths w.r.t. M as M

= M +k +1.

Each of these paths is of length at least .


EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 576/604
Analysis
Lemma 6
P is of length at least +1. This shows that the length of a
shortest augmenting path increases between two phases of the
Hopcroft-Karp algorithm.
Proof.

If P does not intersect any of the P


1
, . . . , P
k
, this follows
from the maximality of the set P
1
, . . . , P
k
.

Otherwise, at least one edge from P coincides with an edge


from paths P
1
, . . . , P
k
.

This edge is not contained in A.

Hence, A k +P 1.

The lower bound on A gives (k +1) A k +P 1,


and hence P +1.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 577/604
Analysis
Lemma 6
P is of length at least +1. This shows that the length of a
shortest augmenting path increases between two phases of the
Hopcroft-Karp algorithm.
Proof.

If P does not intersect any of the P


1
, . . . , P
k
, this follows
from the maximality of the set P
1
, . . . , P
k
.

Otherwise, at least one edge from P coincides with an edge


from paths P
1
, . . . , P
k
.

This edge is not contained in A.

Hence, A k +P 1.

The lower bound on A gives (k +1) A k +P 1,


and hence P +1.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 577/604
Analysis
Lemma 6
P is of length at least +1. This shows that the length of a
shortest augmenting path increases between two phases of the
Hopcroft-Karp algorithm.
Proof.

If P does not intersect any of the P


1
, . . . , P
k
, this follows
from the maximality of the set P
1
, . . . , P
k
.

Otherwise, at least one edge from P coincides with an edge


from paths P
1
, . . . , P
k
.

This edge is not contained in A.

Hence, A k +P 1.

The lower bound on A gives (k +1) A k +P 1,


and hence P +1.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 577/604
Analysis
Lemma 6
P is of length at least +1. This shows that the length of a
shortest augmenting path increases between two phases of the
Hopcroft-Karp algorithm.
Proof.

If P does not intersect any of the P


1
, . . . , P
k
, this follows
from the maximality of the set P
1
, . . . , P
k
.

Otherwise, at least one edge from P coincides with an edge


from paths P
1
, . . . , P
k
.

This edge is not contained in A.

Hence, A k +P 1.

The lower bound on A gives (k +1) A k +P 1,


and hence P +1.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 577/604
Analysis
Lemma 6
P is of length at least +1. This shows that the length of a
shortest augmenting path increases between two phases of the
Hopcroft-Karp algorithm.
Proof.

If P does not intersect any of the P


1
, . . . , P
k
, this follows
from the maximality of the set P
1
, . . . , P
k
.

Otherwise, at least one edge from P coincides with an edge


from paths P
1
, . . . , P
k
.

This edge is not contained in A.

Hence, A k +P 1.

The lower bound on A gives (k +1) A k +P 1,


and hence P +1.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 577/604
Analysis
Lemma 6
P is of length at least +1. This shows that the length of a
shortest augmenting path increases between two phases of the
Hopcroft-Karp algorithm.
Proof.

If P does not intersect any of the P


1
, . . . , P
k
, this follows
from the maximality of the set P
1
, . . . , P
k
.

Otherwise, at least one edge from P coincides with an edge


from paths P
1
, . . . , P
k
.

This edge is not contained in A.

Hence, A k +P 1.

The lower bound on A gives (k +1) A k +P 1,


and hence P +1.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 577/604
Analysis
If the shortest augmenting path w.r.t. a matching M has edges
then the cardinality of the maximum matching is of size at most
M +
V
+1
.
Proof.
The symmetric dierence between M and M

contains
M

M vertex-disjoint augmenting paths. Each of these


paths contains at least +1 vertices. Hence, there can be at
most
V
+1
of them.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 578/604
Analysis
If the shortest augmenting path w.r.t. a matching M has edges
then the cardinality of the maximum matching is of size at most
M +
V
+1
.
Proof.
The symmetric dierence between M and M

contains
M

M vertex-disjoint augmenting paths. Each of these


paths contains at least +1 vertices. Hence, there can be at
most
V
+1
of them.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 578/604
Analysis
Lemma 7
The Hopcroft-Karp algorithm requires at most 2

V phases.
Proof.

After iteration |

V] the length of a shortest augmenting


path must be at least |

V] +1

V.

Hence, there can be at most 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] the length of a shortest augmenting


path must be at least |

V] +1

V.

Hence, there can be at most 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).

Do a breadth rst search starting at all free vertices in the


left side L.
(alternatively add a super-startnode; connect it to all free vertices
in L and start breadth rst search from there)

The search stops when reaching a free vertex. However, the


current level of the BFS tree is still nished in order to nd a
set F of free vertices (on the right side) that can be reached
via shortest augmenting paths.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 580/604
Analysis

Then a maximal set of shortest path from the leftmost layer


of the tree construction to nodes in F needs to be
computed.

Any such path must visit the layers of the BFS-tree from left
to right.

To go from an odd layer to an even layer it must use a


matching edge.

To go from an even layer to an odd layer edge it can use


edges in the BFS-tree or edges that have been ignored
during BFS-tree construction.

We direct all edges btw. an even node in some layer to an


odd node in layer +1 from left to right.

A DFS search in the resulting graph gives us a maximal set


of vertex disjoint path from left to right in the resulting
graph.
EADS 20 The Hopcroft-Karp Algorithm
Ernst Mayr, Harald Rcke 581/604
s
s
s
s
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
The cycle w y x w
is called a blossom.
w is called the base of the
blossom (even node!!!).
The path u-w path is called
the stem of the blossom.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 583/604
How to nd an augmenting path?
Construct an alternating tree.
u
x
y
w
even nodes
odd nodes
Case 4:
y is already contained
in T as an even vertex
cant ignore y
The cycle w y x w
is called a blossom.
w is called the base of the
blossom (even node!!!).
The path u-w path is called
the stem of the blossom.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 583/604
How to nd an augmenting path?
Construct an alternating tree.
u
x
y
w
even nodes
odd nodes
Case 4:
y is already contained
in T as an even vertex
cant ignore y
The cycle w y x w
is called a blossom.
w is called the base of the
blossom (even node!!!).
The path u-w path is called
the stem of the blossom.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 583/604
Flowers and Blossoms
Denition 9
A ower in a graph G = (V, E) w.r.t. a matching M and a (free)
root node r, is a subgraph with two components:

A stem is an even length alternating path that starts at the


root node r and terminates at some node w. We permit the
possibility that r = w (empty stem).

A blossom is an odd length alternating cycle that starts and


terminates at the terminal node w of a stem and has no
other node in common with the stem. w is called the base
of the blossom.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 584/604
Flowers and Blossoms
Denition 9
A ower in a graph G = (V, E) w.r.t. a matching M and a (free)
root node r, is a subgraph with two components:

A stem is an even length alternating path that starts at the


root node r and terminates at some node w. We permit the
possibility that r = w (empty stem).

A blossom is an odd length alternating cycle that starts and


terminates at the terminal node w of a stem and has no
other node in common with the stem. w is called the base
of the blossom.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 584/604
Flowers and Blossoms
Denition 9
A ower in a graph G = (V, E) w.r.t. a matching M and a (free)
root node r, is a subgraph with two components:

A stem is an even length alternating path that starts at the


root node r and terminates at some node w. We permit the
possibility that r = w (empty stem).

A blossom is an odd length alternating cycle that starts and


terminates at the terminal node w of a stem and has no
other node in common with the stem. w is called the base
of the blossom.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 584/604
Flowers and Blossoms
1
2
3
4
5
6
7
8
9
1 2 3 4 5
6
7
8
9
10
11
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 585/604
Flowers and Blossoms
Properties:
1. A stem spans 2 +1 nodes and contains matched edges
for some integer 0.
2. A blossom spans 2k +1 nodes and contains k matched
edges for some integer k 1. The matched edges match all
nodes of the blossom except the base.
3. The base of a blossom is an even node (if the stem is part of
an alternating tree starting at r).
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 586/604
Flowers and Blossoms
Properties:
1. A stem spans 2 +1 nodes and contains matched edges
for some integer 0.
2. A blossom spans 2k +1 nodes and contains k matched
edges for some integer k 1. The matched edges match all
nodes of the blossom except the base.
3. The base of a blossom is an even node (if the stem is part of
an alternating tree starting at r).
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 586/604
Flowers and Blossoms
Properties:
1. A stem spans 2 +1 nodes and contains matched edges
for some integer 0.
2. A blossom spans 2k +1 nodes and contains k matched
edges for some integer k 1. The matched edges match all
nodes of the blossom except the base.
3. The base of a blossom is an even node (if the stem is part of
an alternating tree starting at r).
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 586/604
Flowers and Blossoms
Properties:
4. Every node x in the blossom (except its base) is reachable
from the root (or from the base of the blossom) through two
distinct alternating paths; one with even and one with odd
length.
5. The even alternating path to x terminates with a matched
edge and the odd path with an unmatched edge.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 587/604
Flowers and Blossoms
Properties:
4. Every node x in the blossom (except its base) is reachable
from the root (or from the base of the blossom) through two
distinct alternating paths; one with even and one with odd
length.
5. The even alternating path to x terminates with a matched
edge and the odd path with an unmatched edge.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 587/604
Flowers and Blossoms
1 2 3 4 5
6
7
8
9
10
11
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 588/604
When during the alternating tree construction we discover a
blossom B we replace the graph G by G

= G/B, which is
obtained from G by contracting the blossom B.

Delete all vertices in B (and its incident edges) from G.

Add a new (pseudo-)vertex b. The new vertex b is


connected to all vertices in V \ B that had at least one edge
to a vertex from B.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 589/604
When during the alternating tree construction we discover a
blossom B we replace the graph G by G

= G/B, which is
obtained from G by contracting the blossom B.

Delete all vertices in B (and its incident edges) from G.

Add a new (pseudo-)vertex b. The new vertex b is


connected to all vertices in V \ B that had at least one edge
to a vertex from B.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 589/604
When during the alternating tree construction we discover a
blossom B we replace the graph G by G

= G/B, which is
obtained from G by contracting the blossom B.

Delete all vertices in B (and its incident edges) from G.

Add a new (pseudo-)vertex b. The new vertex b is


connected to all vertices in V \ B that had at least one edge
to a vertex from B.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 589/604
Shrinking Blossoms

Edges of T that connect a node u


not in B to a node in B become
tree edges in T

connecting u to
b.

Matching edges (there is at most


one) that connect a node u not in
B to a node in B become
matching edges in M

Nodes that are connected in G to


at least one node in B become
connected to b in G

.
w
x y
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 590/604
Shrinking Blossoms

Edges of T that connect a node u


not in B to a node in B become
tree edges in T

connecting u to
b.

Matching edges (there is at most


one) that connect a node u not in
B to a node in B become
matching edges in M

Nodes that are connected in G to


at least one node in B become
connected to b in G

.
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

be the matching in the contracted graph.


Lemma 10
If G

contains an augmenting path p

starting at r (or the


pseudo-node containing r) w.r.t. to the matching 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

be the matching in the contracted graph.


Lemma 10
If G

contains an augmenting path p

starting at r (or the


pseudo-node containing r) w.r.t. to the matching 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

does not contain b it is also an augmenting path in G.


Case 1: non-empty stem

Next suppose that the stem is non-empty.


P
1
P
3
r
i b
q
P
1
P
3
r
i
w
k
q
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 593/604
Proof.
If p

does not contain b it is also an augmenting path in G.


Case 1: non-empty stem

Next suppose that the stem is non-empty.


P
1
P
3
r
i b
q
P
1
P
3
r
i
w
k
q
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 593/604
Proof.
If p

does not contain b it is also an augmenting path in G.


Case 1: non-empty stem

Next suppose that the stem is non-empty.


P
1
P
3
r
i b
q
P
1
P
3
r
i
w
k
q
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 593/604
Proof.
If p

does not contain b it is also an augmenting path in G.


Case 1: non-empty stem

Next suppose that the stem is non-empty.


P
1
P
3
r
i b
q
P
1
P
3
r
i
w
k
q
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 593/604

After the expansion must be incident to some node in the


blossom. Let this node be k.

If k w there is an alternating path P


2
from w to k that
ends in a matching edge.

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

If the stem is empty then after expanding the blossom,


w = r.
P
3
b
q
P
3
w
k
q

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

If the stem is empty then after expanding the blossom,


w = r.
P
3
b
q
P
3
w
k
q

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

If the stem is empty then after expanding the blossom,


w = r.
P
3
b
q
P
3
w
k
q

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

If the stem is empty then after expanding the blossom,


w = r.
P
3
b
q
P
3
w
k
q

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

contains an augmenting path from r (or the


pseudo-node containing r) to q w.r.t. M

.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 596/604
Proof.

If P does not contain a node from B there is nothing to


prove.

We can assume that r and q are the only free nodes in G.


Case 1: empty stem
Let i be the last node on the path P that is part of the blossom.
P is of the form P
1
(i, j) P
2
, for some node j and (i, j) is
unmatched.
(b, j) P
2
is an augmenting path in the contracted network.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 597/604
Proof.

If P does not contain a node from B there is nothing to


prove.

We can assume that r and q are the only free nodes in G.


Case 1: empty stem
Let i be the last node on the path P that is part of the blossom.
P is of the form P
1
(i, j) P
2
, for some node j and (i, j) is
unmatched.
(b, j) P
2
is an augmenting path in the contracted network.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 597/604
Proof.

If P does not contain a node from B there is nothing to


prove.

We can assume that r and q are the only free nodes in G.


Case 1: empty stem
Let i be the last node on the path P that is part of the blossom.
P is of the form P
1
(i, j) P
2
, for some node j and (i, j) is
unmatched.
(b, j) P
2
is an augmenting path in the contracted network.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 597/604
Proof.

If P does not contain a node from B there is nothing to


prove.

We can assume that r and q are the only free nodes in G.


Case 1: empty stem
Let i be the last node on the path P that is part of the blossom.
P is of the form P
1
(i, j) P
2
, for some node j and (i, j) is
unmatched.
(b, j) P
2
is an augmenting path in the contracted network.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 597/604
Proof.

If P does not contain a node from B there is nothing to


prove.

We can assume that r and q are the only free nodes in G.


Case 1: empty stem
Let i be the last node on the path P that is part of the blossom.
P is of the form P
1
(i, j) P
2
, for some node j and (i, j) is
unmatched.
(b, j) P
2
is an augmenting path in the contracted network.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 597/604
Proof.

If P does not contain a node from B there is nothing to


prove.

We can assume that r and q are the only free nodes in G.


Case 1: empty stem
Let i be the last node on the path P that is part of the blossom.
P is of the form P
1
(i, j) P
2
, for some node j and (i, j) is
unmatched.
(b, j) P
2
is an augmenting path in the contracted network.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 597/604
Algorithm 50 search(r, found)
1: set

A(i) A(i) for all nodes i
2: found false
3: unlabel all nodes;
4: give an even label to r and initialize list r
5: while list do
6: delete a node i from list
7: examine(i, found)
8: if found = true then return
Search for an augmenting path
starting at r.
Algorithm 50 search(r, found)
1: set

A(i) A(i) for all nodes i
2: found false
3: unlabel all nodes;
4: give an even label to r and initialize list r
5: while list do
6: delete a node i from list
7: examine(i, found)
8: if found = true then return
A(i) contains neighbours of node i.
We create a copy

A(i) so that we later
can shrink blossoms.
Algorithm 50 search(r, found)
1: set

A(i) A(i) for all nodes i
2: found false
3: unlabel all nodes;
4: give an even label to r and initialize list r
5: while list do
6: delete a node i from list
7: examine(i, found)
8: if found = true then return
found is just a Boolean that allows
to abort the search process...
Algorithm 50 search(r, found)
1: set

A(i) A(i) for all nodes i
2: found false
3: unlabel all nodes;
4: give an even label to r and initialize list r
5: while list do
6: delete a node i from list
7: examine(i, found)
8: if found = true then return
In the beginning no node is in the tree.
Algorithm 50 search(r, found)
1: set

A(i) A(i) for all nodes i
2: found false
3: unlabel all nodes;
4: give an even label to r and initialize list r
5: while list do
6: delete a node i from list
7: examine(i, found)
8: if found = true then return
Put the root in the tree.
list could also be a set or a stack.
Algorithm 50 search(r, found)
1: set

A(i) A(i) for all nodes i
2: found false
3: unlabel all nodes;
4: give an even label to r and initialize list r
5: while list do
6: delete a node i from list
7: examine(i, found)
8: if found = true then return
As long as there are nodes with
unexamined neighbours...
Algorithm 50 search(r, found)
1: set

A(i) A(i) for all nodes i
2: found false
3: unlabel all nodes;
4: give an even label to r and initialize list r
5: while list do
6: delete a node i from list
7: examine(i, found)
8: if found = true then return
...examine the next one
Algorithm 50 search(r, found)
1: set

A(i) A(i) for all nodes i
2: found false
3: unlabel all nodes;
4: give an even label to r and initialize list r
5: while list do
6: delete a node i from list
7: examine(i, found)
8: if found = true then return
If you found augmenting path
abort and start from next root.
Algorithm 50 examine(i, found)
1: for all j

A(i) do
2: if j is even then contract(i, j) and return
3: if j is unmatched then
4: q j;
5: pred(q) i;
6: found true;
7: return
8: if j is matched and unlabeled then
9: pred(j) i;
10: pred(mate(j)) j;
11: add mate(j) to list
Examine the neighbours of a node i
Algorithm 50 examine(i, found)
1: for all j

A(i) do
2: if j is even then contract(i, j) and return
3: if j is unmatched then
4: q j;
5: pred(q) i;
6: found true;
7: return
8: if j is matched and unlabeled then
9: pred(j) i;
10: pred(mate(j)) j;
11: add mate(j) to list
For all neighbours j do...
Algorithm 50 examine(i, found)
1: for all j

A(i) do
2: if j is even then contract(i, j) and return
3: if j is unmatched then
4: q j;
5: pred(q) i;
6: found true;
7: return
8: if j is matched and unlabeled then
9: pred(j) i;
10: pred(mate(j)) j;
11: add mate(j) to list
You have found a blossom...
Algorithm 50 examine(i, found)
1: for all j

A(i) do
2: if j is even then contract(i, j) and return
3: if j is unmatched then
4: q j;
5: pred(q) i;
6: found true;
7: return
8: if j is matched and unlabeled then
9: pred(j) i;
10: pred(mate(j)) j;
11: add mate(j) to list
You have found a free node which
gives you an augmenting path.
Algorithm 50 examine(i, found)
1: for all j

A(i) do
2: if j is even then contract(i, j) and return
3: if j is unmatched then
4: q j;
5: pred(q) i;
6: found true;
7: return
8: if j is matched and unlabeled then
9: pred(j) i;
10: pred(mate(j)) j;
11: add mate(j) to list
If you nd a matched node that is not
in the tree you grow...
Algorithm 50 examine(i, found)
1: for all j

A(i) do
2: if j is even then contract(i, j) and return
3: if j is unmatched then
4: q j;
5: pred(q) i;
6: found true;
7: return
8: if j is matched and unlabeled then
9: pred(j) i;
10: pred(mate(j)) j;
11: add mate(j) to list
mate(j) is a new node from
which you can grow further.
Algorithm 50 contract(i, j)
1: trace pred-indices of i and j to identify a blossom B
2: create new node b and set

A(b)
xB

A(x)
3: label b even and add to list
4: update

A(j)

A(j) b for each j

A(b)
5: form a circular double linked list of nodes in B
6: delete nodes in B from the graph
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 600/604
Contract blossom identied by
nodes i and j
Algorithm 50 contract(i, j)
1: trace pred-indices of i and j to identify a blossom B
2: create new node b and set

A(b)
xB

A(x)
3: label b even and add to list
4: update

A(j)

A(j) b for each j

A(b)
5: form a circular double linked list of nodes in B
6: delete nodes in B from the graph
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 600/604
Get all nodes of the blossom.
Time: O(m)
Algorithm 50 contract(i, j)
1: trace pred-indices of i and j to identify a blossom B
2: create new node b and set

A(b)
xB

A(x)
3: label b even and add to list
4: update

A(j)

A(j) b for each j

A(b)
5: form a circular double linked list of nodes in B
6: delete nodes in B from the graph
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 600/604
Identify all neighbours of b.
Time: O(m) (how?)
Algorithm 50 contract(i, j)
1: trace pred-indices of i and j to identify a blossom B
2: create new node b and set

A(b)
xB

A(x)
3: label b even and add to list
4: update

A(j)

A(j) b for each j

A(b)
5: form a circular double linked list of nodes in B
6: delete nodes in B from the graph
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 600/604
b will be an even node, and it has
unexamined neighbours.
Algorithm 50 contract(i, j)
1: trace pred-indices of i and j to identify a blossom B
2: create new node b and set

A(b)
xB

A(x)
3: label b even and add to list
4: update

A(j)

A(j) b for each j

A(b)
5: form a circular double linked list of nodes in B
6: delete nodes in B from the graph
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 600/604
Every node that was adjacent to a node
in B is now adjacent to b
Algorithm 50 contract(i, j)
1: trace pred-indices of i and j to identify a blossom B
2: create new node b and set

A(b)
xB

A(x)
3: label b even and add to list
4: update

A(j)

A(j) b for each j

A(b)
5: form a circular double linked list of nodes in B
6: delete nodes in B from the graph
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 600/604
Only for making a blossom
expansion easier.
Algorithm 50 contract(i, j)
1: trace pred-indices of i and j to identify a blossom B
2: create new node b and set

A(b)
xB

A(x)
3: label b even and add to list
4: update

A(j)

A(j) b for each j

A(b)
5: form a circular double linked list of nodes in B
6: delete nodes in B from the graph
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 600/604
Only delete links from nodes not in B to B.
When expanding the blossom again we can
recreate these links in time O(m).
Analysis

A contraction operation can be performed in time O(m).


Note, that any graph created will have at most m edges.

The time between two contraction-operation is basically a


BFS/DFS on a graph. Hence takes time O(m).

There are at most n contractions as each contraction


reduces the number of vertices.

The expansion can trivially be done in the same time as


needed for all contractions.

An augmentation requires time O(n). There are at most n


of them.

In total the running time is at most


n (O(mn) +O(n)) = O(mn
2
) .
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 601/604
Analysis

A contraction operation can be performed in time O(m).


Note, that any graph created will have at most m edges.

The time between two contraction-operation is basically a


BFS/DFS on a graph. Hence takes time O(m).

There are at most n contractions as each contraction


reduces the number of vertices.

The expansion can trivially be done in the same time as


needed for all contractions.

An augmentation requires time O(n). There are at most n


of them.

In total the running time is at most


n (O(mn) +O(n)) = O(mn
2
) .
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 601/604
Analysis

A contraction operation can be performed in time O(m).


Note, that any graph created will have at most m edges.

The time between two contraction-operation is basically a


BFS/DFS on a graph. Hence takes time O(m).

There are at most n contractions as each contraction


reduces the number of vertices.

The expansion can trivially be done in the same time as


needed for all contractions.

An augmentation requires time O(n). There are at most n


of them.

In total the running time is at most


n (O(mn) +O(n)) = O(mn
2
) .
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 601/604
Analysis

A contraction operation can be performed in time O(m).


Note, that any graph created will have at most m edges.

The time between two contraction-operation is basically a


BFS/DFS on a graph. Hence takes time O(m).

There are at most n contractions as each contraction


reduces the number of vertices.

The expansion can trivially be done in the same time as


needed for all contractions.

An augmentation requires time O(n). There are at most n


of them.

In total the running time is at most


n (O(mn) +O(n)) = O(mn
2
) .
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 601/604
Analysis

A contraction operation can be performed in time O(m).


Note, that any graph created will have at most m edges.

The time between two contraction-operation is basically a


BFS/DFS on a graph. Hence takes time O(m).

There are at most n contractions as each contraction


reduces the number of vertices.

The expansion can trivially be done in the same time as


needed for all contractions.

An augmentation requires time O(n). There are at most n


of them.

In total the running time is at most


n (O(mn) +O(n)) = O(mn
2
) .
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 601/604
Analysis

A contraction operation can be performed in time O(m).


Note, that any graph created will have at most m edges.

The time between two contraction-operation is basically a


BFS/DFS on a graph. Hence takes time O(m).

There are at most n contractions as each contraction


reduces the number of vertices.

The expansion can trivially be done in the same time as


needed for all contractions.

An augmentation requires time O(n). There are at most n


of them.

In total the running time is at most


n (O(mn) +O(n)) = O(mn
2
) .
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 601/604
r
i
j
q
b j
q
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 602/604
Case 2: non-empty stem
Let P
3
be alternating path from r to w. Dene M
+
= M P
3
.
In M
+
, r is matched and w is unmatched.
G must contain an augmenting path w.r.t. matching M
+
, since M
and M
+
have same cardinality.
This path must go between w and q as these are the only
unmatched vertices w.r.t. M
+
.
For M

+
the blossom has an empty stem. Case 1 applies.
G

has an augmenting path w.r.t. M

+
. It must also have an
augmenting path w.r.t. M

, as both matchings have the same


cardinality.
This path must go between r and q.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 603/604
Case 2: non-empty stem
Let P
3
be alternating path from r to w. Dene M
+
= M P
3
.
In M
+
, r is matched and w is unmatched.
G must contain an augmenting path w.r.t. matching M
+
, since M
and M
+
have same cardinality.
This path must go between w and q as these are the only
unmatched vertices w.r.t. M
+
.
For M

+
the blossom has an empty stem. Case 1 applies.
G

has an augmenting path w.r.t. M

+
. It must also have an
augmenting path w.r.t. M

, as both matchings have the same


cardinality.
This path must go between r and q.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 603/604
Case 2: non-empty stem
Let P
3
be alternating path from r to w. Dene M
+
= M P
3
.
In M
+
, r is matched and w is unmatched.
G must contain an augmenting path w.r.t. matching M
+
, since M
and M
+
have same cardinality.
This path must go between w and q as these are the only
unmatched vertices w.r.t. M
+
.
For M

+
the blossom has an empty stem. Case 1 applies.
G

has an augmenting path w.r.t. M

+
. It must also have an
augmenting path w.r.t. M

, as both matchings have the same


cardinality.
This path must go between r and q.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 603/604
Case 2: non-empty stem
Let P
3
be alternating path from r to w. Dene M
+
= M P
3
.
In M
+
, r is matched and w is unmatched.
G must contain an augmenting path w.r.t. matching M
+
, since M
and M
+
have same cardinality.
This path must go between w and q as these are the only
unmatched vertices w.r.t. M
+
.
For M

+
the blossom has an empty stem. Case 1 applies.
G

has an augmenting path w.r.t. M

+
. It must also have an
augmenting path w.r.t. M

, as both matchings have the same


cardinality.
This path must go between r and q.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 603/604
Case 2: non-empty stem
Let P
3
be alternating path from r to w. Dene M
+
= M P
3
.
In M
+
, r is matched and w is unmatched.
G must contain an augmenting path w.r.t. matching M
+
, since M
and M
+
have same cardinality.
This path must go between w and q as these are the only
unmatched vertices w.r.t. M
+
.
For M

+
the blossom has an empty stem. Case 1 applies.
G

has an augmenting path w.r.t. M

+
. It must also have an
augmenting path w.r.t. M

, as both matchings have the same


cardinality.
This path must go between r and q.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 603/604
Case 2: non-empty stem
Let P
3
be alternating path from r to w. Dene M
+
= M P
3
.
In M
+
, r is matched and w is unmatched.
G must contain an augmenting path w.r.t. matching M
+
, since M
and M
+
have same cardinality.
This path must go between w and q as these are the only
unmatched vertices w.r.t. M
+
.
For M

+
the blossom has an empty stem. Case 1 applies.
G

has an augmenting path w.r.t. M

+
. It must also have an
augmenting path w.r.t. M

, as both matchings have the same


cardinality.
This path must go between r and q.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 603/604
Case 2: non-empty stem
Let P
3
be alternating path from r to w. Dene M
+
= M P
3
.
In M
+
, r is matched and w is unmatched.
G must contain an augmenting path w.r.t. matching M
+
, since M
and M
+
have same cardinality.
This path must go between w and q as these are the only
unmatched vertices w.r.t. M
+
.
For M

+
the blossom has an empty stem. Case 1 applies.
G

has an augmenting path w.r.t. M

+
. It must also have an
augmenting path w.r.t. M

, as both matchings have the same


cardinality.
This path must go between r and q.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 603/604
Case 2: non-empty stem
Let P
3
be alternating path from r to w. Dene M
+
= M P
3
.
In M
+
, r is matched and w is unmatched.
G must contain an augmenting path w.r.t. matching M
+
, since M
and M
+
have same cardinality.
This path must go between w and q as these are the only
unmatched vertices w.r.t. M
+
.
For M

+
the blossom has an empty stem. Case 1 applies.
G

has an augmenting path w.r.t. M

+
. It must also have an
augmenting path w.r.t. M

, as both matchings have the same


cardinality.
This path must go between r and q.
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 603/604
Example: Blossom Algorithm
0
1 2 3 4 5 6
7 8 9 10
11
12 13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
0
1 2 3 4 5 6
7 8 9 10
11
12 13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
0
1 2 3 4 5 6
7 8 9 10
11
12 13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
0
1 2 3 4 5 6
7 8 9 10
11
12 13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
0
1 2 3 4 5 6
7 8 9 10
11
12 13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
0
1 2 3 4 5 6
7 8 9 10
11
12 13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
0
1 2 3 4 5 6
7 8 9 10
11
12 13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
1
0
1 2 3 4 5 6
7 9 10
13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
1
0
1 2 3 4 5 6
7 9 10
13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
1
0
1 2 3 4 5 6
7 9 10
13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
2 3 4 5 6
9 10
13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
2 3 4 5 6
9 10
13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
2 3 4 5 6
9 10
13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
2 3 4 5 6
9 10
13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
2 3 4 5 6
9 10
13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
2 3 4 5 6
9 10
13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
2
3
3 4 5 6
10
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
2
3
3 4 5 6
10
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
2
3
3 4 5 6
10
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
2
3
3 4 5 6
10
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
2 3 4 5 6
9 10
13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
2 3 4 5 6
9 10
13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
1
2
0
1 2 3 4 5 6
7 9 10
13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
1
2
0
1 2 3 4 5 6
7 9 10
13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
2
0
1 2 3 4 5 6
7 8 9 10
11
12 13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
2
0
1 2 3 4 5 6
7 8 9 10
11
12 13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604
Example: Blossom Algorithm
2
0
1 2 3 4 5 6
7 8 9 10
11
12 13
14
15
EADS 21 Maximum Matching in General Graphs
Ernst Mayr, Harald Rcke 604/604

You might also like