Algorithm Design and Analysis LETURE 2 Network Flow Finish bipartite matching apacity-scaling algorithm Adam Smith 0//0 A. Smith; based on slides by E. Demaine,. Leiserson, S. Raskhodnikova, K. Wayne
Marriage Theorem Marriage Theorem. [Frobenius 97, Hall 935] Let G = (L R, E) be a bipartite graph with L = R. Then, G has a perfect matching iff N(S) S for all subsets S L. Pf. This was the previous observation. ' 2 3 2' 3' No perfect matching: S = { 2, 4, 5 } N(S) = { 2', 5' }. 4 4' L 5 5' R
Proof of Marriage Theorem Pf. Suppose G does not have a perfect matching. Formulate as a max flow problem with constraints on edges from L to R and let (A, B) be min cut in G'. Key property # of this graph: min-cut cannot use edges. So cap(a, B) = L B + R A Key property #2: integral flow is still a matching By max-flow min-cut, cap(a, B) < L. hoose S = L A. Since min cut can't use edges: N(S) R A. N(S ) R A = cap(a, B) - L B < L - L B = S. s G' A 2 2' ' S = {2, 4, 5} L B = {, 3} 4 3 3' 4' t R A = {2', 5'} N(S) = {2', 5'} 5 5'
Bipartite Matching: Running Time Which max flow algorithm to use for bipartite matching? Generic augmenting path: O(m val(f*) ) = O(mn). apacity scaling: O(m 2 log ) = O(m 2 ). Shortest augmenting path (not covered in class): O(m n /2 ). Non-bipartite matching. Structure of non-bipartite graphs is more complicated, but well-understood. [Tutte-Berge, Edmonds-Galai] Blossom algorithm: O(n 4 ). [Edmonds 965] Best known: O(m n /2 ). [Micali-Vazirani 980] Recently: better algorithms for dense graphs, e.g. O(n 2.38 ) [Harvey, 2006]
Exercise A bipartite graph is k-regular if L = R and every vertex (regardless of which side it is on) has exactly k neighbors Prove or disprove: every k-regular bipartite graph has a perfect matching
Faster algorithms when capacities are large
Ford-Fulkerson: Exponential Number of Augmentations Q. Is generic Ford-Fulkerson algorithm polynomial in input size? m, n, and log A. No. If max capacity is, then algorithm can take iterations. X0 0 X0 X0 s X 0 t s X0 X 0 t 0 X0 X0 X0 2 2 Intuition: we re choosing the wrong paths!
hoosing Good Augmenting Paths Use care when selecting augmenting paths. Some choices lead to exponential algorithms. lever choices lead to polynomial algorithms. If capacities are irrational, algorithm not guaranteed to terminate! Goal: choose augmenting paths so that: an find augmenting paths efficiently. Few iterations. hoose augmenting paths with: [Edmonds-Karp 972, Dinitz 970] Max bottleneck capacity. Sufficiently large bottleneck capacity. Fewest number of edges.
apacity Scaling Intuition. hoosing path with highest bottleneck capacity increases flow by max possible amount. Don't worry about finding exact highest bottleneck path. Maintain scaling parameter. G f ( ) = subgraph of the residual graph with only arcs ofcapacity at least. 4 4 0 02 0 02 s t s t 22 70 22 70 2 2 G f G f (00)
apacity Scaling Scaling-Max-Flow(G, s, t, c) { foreach e E f(e) 0 smallest power of 2 greater than or equal to G f residual graph } while ( ) { G f ( ) -residual graph while (there exists augmenting path P in G f ( )) { f augment(f, c, P) // augment flow by update G f ( ) } / 2 } return f
apacity Scaling: orrectness Assumption. All edge capacities are integers between and. Integrality invariant. All flow and residual capacity values are integral. orrectness. If the algorithm terminates, then f is a max flow. Pf. By integrality invariant, when = G f ( ) = G f. Upon termination of = phase, there are no augmenting paths.
apacity Scaling: Running Time Lemma. The outer while loop repeats + log 2 times. Pf. Initially < 2. decreases by a factor of 2 each iteration. Lemma 2. Let f be the flow at the end of a -scaling phase. Then the value of the maximum flow f* is at most v(f) + m. proof on next slide (Sanity check: v(f*) v(f) m, and shrinks, so v(f) converges towards v(f*) ) Lemma 3. There are at most 2m augmentations per scaling phase. Let f be the flow at the end of the previous scaling phase. Lemma 2 v(f*) v(f) + m (2 ). Each augmentation in a -phase increases v(f) by at least. Theorem. The scaling max-flow algorithm finds a max flow in O(m log ) augmentations. It can be implemented to run in O(m 2 log ) time. (Why?)
apacity Scaling: Running Time Lemma 2. Let f be the flow at the end of a -scaling phase. Then value of the maximum flow is at most v(f) + m. Pf. (almost identical to proof of max-flow min-cut theorem) We show that at the end of a -phase, there exists a cut (A, B) such that cap(a, B) v(f) + m. hoose A to be the set of nodes reachable from s in G f ( ). By definition of A, s A. By definition of f, t A. A B t s So v(f*)-v(f) cap(a,b) v(f) m original network
Best Known Algorithms For Max Flow Reminder: The scaling max-flow algorithm runs in O(m 2 log ) time. urrently there are algorithms that run in time O(mn log n) O(n 3 ) O(min(n 2/3, m /2 ) m log n log ) Active topic of research: Flow algorithms for specific types of graphs Special cases (bipartite matching, etc) Multi-commodity flow
What you should know about max flow How Ford-Fulkerson works How to use it to find min cuts How to use it to solve other problems (more examples coming) max matching project selection edge-disjoint paths vertex-disjoint paths To study: Review lecture notes/ textbook Solved exercises in book Homework problems Homework exercises Solve lots of problems!