Hskladjas
Hskladjas
Hskladjas
Andrew McGregor
1/18
Outline
2/18
Bipartite Matchings
Problem
I Input: Bipartite graph B = (U, V , E ) where U, V are disjoint sets of
vertices and E is a set of edges between U and V .
I Output: The matching (i.e., subset of E where no two edges share a
vertex) of maximum size.
3/18
Intersection of Matroids
Theorem
For matroids (E , I) and (E , I 0 ), the largest set in I ∩ I 0 can be found in
time O(|E |3 · C (I, I 0 )) where C (I, I 0 ) is time to check i ∈ I or i ∈ I 0 .
We won’t prove this general theorem but will focus on the special case of
bipartite matching. Note that there is no analogous theorem for the
intersection of three matroids.
4/18
Augmenting Paths Definitions
Let M be a matching in a bipartite graph B = (U, V , E ). A free vertex is
a node not incident to any edge in M. E.g., the blue vertices in
U
Definition
An augmenting path is an odd sequence of edges that begins and ends at
(different) free vertices and alternates between matching edges e ∈ M
and non-matching edges e ∈ E − M.
Definition
If P is an augmenting path for matching M, the symmetric difference of
M and P is M ⊕ P := (M ∪ P) − (M ∩ P).
U
5/18
Augmenting Paths Properties
Lemma
For matching M and augmenting path P, M ⊕ P is a matching and
|M ⊕ P| = |M| + 1 .
Lemma
If M is non-maximum matching, there exists an augmenting path.
6/18
Finding an augmenting path allows us to “grow” matching
Lemma
For matching M and augmenting path P, M ⊕ P is a matching and
|M ⊕ P| = |M| + 1 .
Proof.
I A matching is a graph where no node has degree > 1
I Size of matching is (number of degree 1 nodes)/2
I Remove edges in P ∩ M and add edges in P \ M:
I Adds one to degree of two nodes that initially were free.
I Degree of interior points of P still have degree 1.
7/18
Augmenting path exists for non-maximum matching
Lemma
If M is non-maximum matching, there exists an augmenting path.
Proof.
I Let M 0 be a matching such that |M 0 | > |M|
I Consider E 0 = M ⊕ M 0 . . . consists of simple paths and cycles whose
edges alternate between M and M 0
8/18
Bipartite Matching Algorithm
Algorithm
I M←∅
I While there exists an augmenting path P: M ← M ⊕ P
I Return M
9/18
Outline
10/18
Recall Kruskal’s Algorithm. . .
Algorithm (Kruskal)
1. Sort edges by non-decreasing weight
2. F = ∅
3. Until F is a spanning tree of G
3.1 Get the next edge e
3.2 If F + e is acyclic then F = F + e
11/18
Union-Find Data Structure
Encodes a set of disjoint sets where each set contains an element
designated as the “label” of the set. E.g.,
12/18
Kruskal’s Algorithm with Union-Find
Algorithm (Kruskal)
1. Sort edges by non-decreasing weight
2. For each vertex v ∈ V : Make-Set(v )
3. F = ∅
4. For each edge e = (u, v ) in E
4.1 If Find(u)6=Find(v ) then Union(u, v ) and F = F + e
13/18
Simple Implementation of Union-Find
1. Each disjoint set is stored as a linked list of nodes
2. Each node consists of three data items:
2.1 name of element
2.2 “label” pointer to label of the set
2.3 “next” pointer to next node in list
3. Also maintain auxiliary pointer for each label to last node of
corresponding list and the size of this list.
a b c d e f
14/18
Union-Find Analysis
Theorem
Consider a sequence of m operations including n Make-Set operations.
Total running time is O(m + n log n).
Proof.
I Total time from Find and Make-Set: O(m)
I Total time from Union: O(n log n)
I Updating next pointers: O(n)
I Updating label pointers: O(n log n) because the label pointer for a
node can be updated at most log2 n times.
15/18
Faster Implementation of Union Find
Theorem
There exists an implementation that, given a sequence of n Make-Set
operations and m total operations, takes O(mα(n)) time where α is the
inverse Ackermann’s function.
Example
2(...2048)
α(n) ≤ 4 for all n ≤ 22 where tower is of height 2048.
16/18
Idea Behind Faster Implementation
I Store each set as a rooted tree.
I Each node encodes an element and pointer to the parent.
I The element at the root is the label of the set.
1. Make-Set(v ): Takes O(1) time to add a single node.
2. Find(v ): Takes O(dv ) time where dv is the depth of v
3. Union-Set(u, v ): O(dv + du ) time
I Perform Find(u), and Find(v )
I Add pointer from root of smaller tree to root of larger tree
More Details: See Section 21.4 of CLRS (3rd edition) or Section 5.1 of
DPV.
17/18
Blank Slide
18/18