Matching
Matching
Variants of Matching
• Graph can be bipartite or general
• Graph can be weighted or unweighted
Terms
• A matching M such that, for all edges e 6∈ M , M ∪ {e} is not a
matching, is called maximal.
• A maximum cardinality matching is called maximum.
• A matching of size |V |/2 is called perfect.
• The weight of a matching M is w(M ) = w(e) .
P
e∈M
Definitions
• An alternating path with respect to a matching M is a path in which
edges alternate between those in M and those not in M .
• A matched vertex is one incident to an edge in M
• An free vertex is a vertex that is not matched
• An augmenting path is an alternating path that starts and ends with a
free vertex.
• A shortest augmenting path is an augmenting path of shortest length.
• Symmetric Difference of 2 sets: A ⊕ B = (A ∪ B) − (A ∩ B)
Augmenting Paths
Facts
• Let M be a matching and P be an augmenting path relative to M .
Then M ⊕ P is a matching and |M ⊕ P | = |M | + 1 .
• Let M be a matching and P1, P2, . . . Pk be k vertex-disjoing augmenting
path relative to M . Then M ⊕ (P1 ∪ P2 ∪ . . . ∪ Pk ) is a matching and
|M ⊕ (P1 ∪ P2 ∪ . . . ∪ Pk )| = |M | + k .
Hopkroft-Karp Algorithm
•M =∅
• Repeat Until P = ∅
– Let P = (P1 ∪ P2 ∪ . . . ∪ Pk ) be a maximal set of vertex disjoint shortest
augmenting paths with respect to M .
– M = M ⊕ (P1 ∪ P2 ∪ . . . ∪ Pk )
Facts
√
Theorem Hopkroft-Karp is an O( nm) time algorithm for bipartite
matching.
A bidding based approach to bipartite matching
Auction Algorithms
1. For each j ∈ G , set pj ← 0 , ownerj ← null .
2. Initiliaze a queue Q to have all bidders B .
3. While Q 6= ∅
(a) i ← Q.Dequeue()
(b) j = argminj 0∈N (i)pj 0
(c) if pj ≤ 1
i. Q.enqueue(ownerj )
ii. ownerj ← i
iii. pj + = δ
4. Return the matching as pairs (ownerj , j)
Analysis
Facts:
• If j ∈ G is unmatched, then pj = 0
• Once j ∈ G is matched, it stays matched.
Choose: δ = 1/(n + 1)
• Applying Lemma 2, we have that |M | ≥ |M 0| − n/(n + 1) which implies
that M is optimal.
• Running time.
– Each iteration either increases a pj by δ or deletes a node from the
Q permanently.
– Thus O(n/(δ) + n) = O(n2) iterations.
– Each iteration can be implemeted in amortized O((m/n) + log n) time,
for a total of O(nm + log n) time.
√
Choose: δ = 1/ n
√
• Applying Lemma 2, we have that |M | ≥ |M 0| − n/ n which implies that
√ √
M is within n of optimal. Therefore we can finish up with n
augmenting paths.
√
• Running time is O( nm) .
Assignment Problem
(v,w)∈E
s.t.
x(v, w) = 1 ∀w ∈ V
X
v∈V
x(v, w) = 1 ∀v ∈ V
X
w∈V
x(v, w) ≥ 0 ∀(v, w) ∈ E
Dual:
max π(v)
X
v∈V
s.t.
π(v) + π(w) ≤ c(v, w) ∀(v, w) ∈ E
Theorem For any set of preferences, a stable marriage exists and can be
found in O(n2) time.
Algorithm
• Proceed in Rounds
• In each round, any unmatched man proposes to his highest ranked
woman who has not yet rejected him.
• Woman accept any proposal if it is preferred to their current v matching
(and prefer anyone to being unmatched).
Properties of Algorithm
Claims:
• The matching is stable.
• Each man is matched to the highest ranked woman he could match in
any stable marriage.
• Each woman is matched to the lowest ranked man she could match in
any stable marriage.