Exposition of the Dinitz algorithm

Similar documents
CMPSCI 611: Advanced Algorithms

Running Time. Assumption. All capacities are integers between 1 and C.

1 Review for Lecture 2 MaxFlow

10 Max-Flow Min-Cut Flows and Capacitated Graphs 10 MAX-FLOW MIN-CUT

The max flow problem. Ford-Fulkerson method. A cut. Lemma Corollary Max Flow Min Cut Theorem. Max Flow Min Cut Theorem

Lecture 2: Network Flows 1

Maximum Flow. Jie Wang. University of Massachusetts Lowell Department of Computer Science. J. Wang (UMass Lowell) Maximum Flow 1 / 27

The min cost flow problem Course notes for Search and Optimization Spring 2004

Algorithms and Theory of Computation. Lecture 11: Network Flow

Algorithm Design and Analysis

The min cost flow problem Course notes for Optimization Spring 2007

Flow Network. The following figure shows an example of a flow network:

Problem set 1. (c) Is the Ford-Fulkerson algorithm guaranteed to produce an acyclic maximum flow?

Algorithms: COMP3121/3821/9101/9801

Algorithm Design and Analysis

CSC 373: Algorithm Design and Analysis Lecture 12

directed weighted graphs as flow networks the Ford-Fulkerson algorithm termination and running time

Agenda. Soviet Rail Network, We ve done Greedy Method Divide and Conquer Dynamic Programming

Preliminaries. Graphs. E : set of edges (arcs) (Undirected) Graph : (i, j) = (j, i) (edges) V = {1, 2, 3, 4, 5}, E = {(1, 3), (3, 2), (2, 4)}

6.046 Recitation 11 Handout

Discrete Optimization 2010 Lecture 3 Maximum Flows

Network Flows made simple

Types of Networks. Internet Telephone Cell Highways Rail Electrical Power Water Sewer Gas

Mathematics for Decision Making: An Introduction. Lecture 13

Flows. Chapter Circulations

Two Applications of Maximum Flow

22 Max-Flow Algorithms

Maximum Flow. Reading: CLRS Chapter 26. CSE 6331 Algorithms Steve Lai

Internet Routing Example

CSE 326: Data Structures Network Flow. James Fogarty Autumn 2007

Lecture 8 Network Optimization Algorithms

Analysis of Algorithms. Outline. Single Source Shortest Path. Andres Mendez-Vazquez. November 9, Notes. Notes

Maximum Flows & Minimum Cuts

Basics on the Graphcut Algorithm. Application for the Computation of the Mode of the Ising Model

Maximum flow problem

CS 1501 Recitation. Xiang Xiao

Algorithms: Lecture 12. Chalmers University of Technology

CS 170 DISCUSSION 10 MAXIMUM FLOW. Raymond Chan raychan3.github.io/cs170/fa17.html UC Berkeley Fall 17

CS 4407 Algorithms Lecture: Shortest Path Algorithms

Graph Algorithms -2: Flow Networks. N. H. N. D. de Silva Dept. of Computer Science & Eng University of Moratuwa

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

The Budget-Constrained Maximum Flow Problem

Lecture 1. 1 Overview. 2 Maximum Flow. COMPSCI 532: Design and Analysis of Algorithms August 26, 2015

Design and Analysis of Algorithms

We say that a flow is feasible for G (or just feasible if the graph and capacity function in question are obvious) if

GRAPH ALGORITHMS Week 7 (13 Nov - 18 Nov 2017)

Part V. Matchings. Matching. 19 Augmenting Paths for Matchings. 18 Bipartite Matching via Flows

Energy minimization via graph-cuts

Standard Diraphs the (unique) digraph with no vertices or edges. (modulo n) for every 1 i n A digraph whose underlying graph is a complete graph.

Lecture 13 Spectral Graph Algorithms

CSCE423/823. Introduction. Flow Networks. Ford-Fulkerson Method. Edmonds-Karp Algorithm. Maximum Bipartite Matching 2/35 CSCE423/823.

Optimality of an Algorithm Solving the Bottleneck Tower of Hanoi Problem

Flows and Cuts. 1 Concepts. CS 787: Advanced Algorithms. Instructor: Dieter van Melkebeek

Max Flow: Algorithms and Applications

Review Questions, Final Exam

CS 138b Computer Algorithm Homework #14. Ling Li, February 23, Construct the level graph

The maximum flow problem

Maximum flow problem (part I)

Breadth-First Search of Graphs

Lecture 21 November 11, 2014

Soviet Rail Network, 1955

Maximum Integer Flows in Directed Planar Graphs with Multiple Sources and Sinks and Vertex Capacities

On improving matchings in trees, via bounded-length augmentations 1

Algorithms. Algorithms 6.4 MAXIMUM FLOW

Recall: Matchings. Examples. K n,m, K n, Petersen graph, Q k ; graphs without perfect matching

Introduction to Graph Theory

III. Linear Programming

Review Questions, Final Exam

Two-Commodity Multiroute Maximum Flow Problem

Maximum skew-symmetric flows and matchings

The Simplest and Smallest Network on Which the Ford-Fulkerson Maximum Flow Procedure May Fail to Terminate

Mathematics for Decision Making: An Introduction. Lecture 8

On shredders and vertex connectivity augmentation

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths

Chapter 7. Network Flow. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

CSC2420: Algorithm Design, Analysis and Theory Fall 2017

Algorithms. Algorithms 6.4 MAXIMUM FLOW

Algorithms 6.4 MAXIMUM FLOW. overview Ford-Fulkerson algorithm analysis Java implementation applications

1 Matchings in Non-Bipartite Graphs

the neumann-cheeger constant of the jungle gym

Chapter 10. Maximum flow

Theorem 5.3. Let E/F, E = F (u), be a simple field extension. Then u is algebraic if and only if E/F is finite. In this case, [E : F ] = deg f u.

Maximum Skew-Symmetric Flows. September Abstract

10.3 Matroids and approximation

CSC2420: Algorithm Design, Analysis and Theory Spring (or Winter for pessimists) 2017

Sequential programs. Uri Abraham. March 9, 2014

Design and Analysis of Algorithms

CMPS 6610 Fall 2018 Shortest Paths Carola Wenk

(1,3) (3,4) (2,2) (1,2) (2,4) t

Dynamic Programming: Shortest Paths and DFA to Reg Exps

Algorithms Booklet. 1 Graph Searching. 1.1 Breadth First Search

Min/Max-Poly Weighting Schemes and the NL vs UL Problem

p 3 p 2 p 4 q 2 q 7 q 1 q 3 q 6 q 5

Dynamic Programming: Shortest Paths and DFA to Reg Exps

Network Flow Problems Luis Goddyn, Math 408

University of Toronto Department of Electrical and Computer Engineering. Final Examination. ECE 345 Algorithms and Data Structures Fall 2016

Single Source Shortest Paths

CSE 202 Homework 4 Matthias Springer, A

Lexicographic Flow. Dexter Kozen Department of Computer Science Cornell University Ithaca, New York , USA. June 25, 2009

Transcription:

Exposition of the Dinitz algorithm Yefim Dinitz and Avraham A. Melkman Department of Computer Science Ben Gurion University of the Negev, 84105 Beer-Sheva, Israel {dinitz,melkman}@cs.bgu.ac.il June 6, 2006 1 The Dinitz algorithm The textbook presents the Edmonds-Karp algorithm for finding the maximum flow in a network. It retains the framework of the Ford-Fulkerson algorithm, but instead of arbitrarily finding an augmenting path it finds a shortest augmenting path. Such a path can be found in O ( E ) time (how?). Somewhat surprisingly, the lengths of the shortest augmenting paths found by the algorithm form a non-decreasing sequence. The textbook shows further that for each given length the number of shortest path of that length encountered by the algorithm cannot exceed E (we prove analogous results in Lemma 3.1 and Theorem 3.2). Therefore the Edmonds-Karp algorithm exhausts its finding of shortest augmenting paths from s to t after O ( E 2) time. Since the length of a shortest path does not exceed V 1, the number of different lengths is no more than V 1. Consequently the Edmonds-Karp algorithm runs in O ( V E 2) time. Like the Edmonds-Karp algorithm, the Dinitz algorithm proceeds by finding shortest augmenting paths, but does so more efficiently: it determines each such path in O ( V ) time, resulting in a O ( V 2 E ) algorithm. The Dinitz algorithm achieves this efficiency by reusing the information gathered in a BFS to find not just one but a number of shortest paths. To this end, when looking for shortest augmenting paths of a fixed length l, it maintains an auxiliary network, the layered network, which contains precisely all current shortest paths from s to t, all of length l. The construction of this layered network, at a total cost of O ( E ), is detailed in section 2. Denote by d f (v) the shortest distance from s to v in G f. The Dinitz algorithm is outlined in Algorithm 2. It can be viewed as being based on 1

the slightly modified version of the Ford-Fulkerson algorithm outlined in Algorithm 1. Algorithm 1 Generalized Ford-Fulkerson(G, c, s, t) 1: f 0; 2: while there is a path from s to t in G f do 3: invariant assertion: f is a flow in N ; 4: find a flow g in N f = (G f, c f, s, t); 5: f f + g; 6: Post-condition of the while loop: f is a maximum flow in N ; Note that in the usual version the flow g found in line 4 is the maximum flow along a single path from s to t. As a finger exercise, prove the correctness of this version. Algorithm 2 Dinitz(G, c, s, t) 1: f 0; construct the residual network N f = (G f, c f, s, t); 2: while there is a path from s to t in G f do 3: invariant assertion: f is a flow in N ; 4: construct the layered network L f = (L f, c f, s, t); 5: find a blocking flow b for L f ; assertion: d f+b (t) > d f (t); 6: f f + b; 7: construct the residual network N f ; 8: Post-condition of the while loop: f is a maximum flow in N ; The blocking flow found in line 5 is constructed by repeatedly extracting an unsaturated path from the layered network, and adding as much flow as possible along the path. Since each such path saturates at least one edge, ablocking flow is found after at most E paths have been extracted. Finding a path from s to t in a layered network of length l takes only O ( l ) = O ( V ) time, by repeatedly stepping back, starting from t, until s is reached. To ensure that s is indeed reached, the algorithm 4 for finding a blocking flow maintains the invariant that all vertices in the layered network are reachable from s. Thus, when a flow along an augmenting path saturates some edges, teh algorithm removes from the layered network any vertex which cannot be reched from s. This clean-up operation, Algorithm 5, takes a total of O( E ) time until a blocking flow is found. Consequently the total cost of finding a blocking flow for the layered network is O( V E ). 2

2 Construction of the layered network Definition 2.1. Let N f = (G f, c f, s, t) be a residual network which contains a path from s to t. Denote by d f (u, v) the length of the shortest path from u to v in G f, and set l = d f (s, t). Let V 0 = {s}, and let V i = {u : d f (s, u) = i}, E i = (V i 1 V i ) E f, 1 i l. The layered network corresponding to N f is its subnetwork whose vertices are V 0 V 1... V l and whose edges are E 1... E l. The layered network is constructed by performing a modified BFS on the residual network, which keeps all edges from one layer to the next (instead of only the first edge that leads to some vertex). Algorithm 3 LayeredNetwork Construction(N f ) 1: V 0 {s}; i 0; 2: while (V i ) and (t / V i ) do 3: V i+1 ; E i+1 ; 4: for each u V i do 5: for each v V such that ( u, v E f ) and (v / V j, j i) do 6: if (v / V i+1 ) then 7: add v to V i+1 ; 8: add u, v to E i+1 ; 9: i i+1 10: if (V i = ) then 11: return L f = (, c f, s, t); assertion: there is no path from s to t in N f 12: L f (V 0... V i, E 1... E i ); 13: return L f = (L f, c f, s, t); Post-condition: if t is reachable from s in N f, then L f is the layered network for N f Lemma 2.2. d f (t)). 1. L f contains all shortest paths from s to t in N f (of length 2. A path from s to t in L f is found in O ( l ) = O ( V ) time, by stepping back from t, layer to layer, taking any edge in L f until s is reached. 3 The number of iterations is O ( V ) Lemma 3.1. CLRS 26.8. Let f be a flow in N, and g a flow in L f. Then d f (t) d f+g (t), with equality if and only if each shortest path from s to t in 3

N f+g is also contained in N f. Proof. For the proof we will pretend that the construction of L f, by the modified BFS, is continued after the layer which contains t, until the network contains all vertices, even those not on shortest paths from s to t in N f, and denote the layered network so obtained by L f. Let p = u 0, u 1,..., u k be a shortest path from s = u 0 to t = u k in N f+g. Thus d f+g (u i ) = i. We will prove by induction that d f (u i ) i, and that there is equality only if u 0, u 1,..., u i is in N f. This is clearly true for u 0 = s. For the induction step it has to be proven that d f (u i+1 ) i + 1, with equality holding if and only if the path u 0, u 1,..., u i+1 is also a path in L f. To this end we establish that d f (u i+1 ) d f (u i ) 1, with equality if and only if u i, u i+1 L f. case 1 u i, u i+1 L f. Then d f (u i+1 ) d f (u i ) = 1. Simply because all edges in L f go from one layer to the next. case 2 u i, u i+1 / L f. case a u i, u i+1 N f. Then d f (u i+1 ) d f (u i ) 0. The only reason that an edge in N f does not appear in L f is that it goes from a layer to the same layer or to a previous one. case b u i, u i+1 / N f, i.e., c f (u i, u i+1 ) = 0. Then d f (u i+1 ) d f (u i ) = 1. The fact that u i, u i+1 is present in N f+g although it is not present in N f, means that it is a regret edge resulting from a positive flow of g on the edge u i+1, u i : 0 < c f+g (u i, u i+1 ) = c f (u i, u i+1 ) g(u i, u i+1 ) = g(u i+1, u i ). Since g is a flow in L f, the edge u i+1, u i necessarily goes from one layer of L f to the next, d f (u i ) d f (u i+1 ) = 1. Theorem 3.2. Algorithm Dinitz terminates after at most V 1 passes through the while-loop. Proof. It suffices to prove the assertion of line 5 in Algorithm Dinitz, after a flow b blocking L f has been found, d f (t) < d f+b (t). Since by Lemma 3.1, d f (t) d f+b (t), let s assume by contradiction that d f (t) = d f+b (t). According to Lemma 3.1 this happens only if there is a path p =< u 0,..., u k >, with u 0 = s and u k = t, that is a shortest path in both N f and N f+b. Since 4

p is a shortest path in N f+g, c f+b (u i, u i+1 ) > 0, i = 0,..., k 1. In other words, c f (u i, u i+1 ) b(u i, u i+1 ) > 0, i = 0,..., k 1. But then the path p is in N f yet is not blocked by the flow b, a contradiction to b being a blocking flow. 4 Construction of a blocking flow Algorithm 4 BlockingFlow(L f ) 1: b 0; M L f ; c c f ; 2: repeat 3: assertion: s is the only vertex in M with zero indegree; 4: find a path p from s to t in M; let its bottleneck capacity be c(p); 5: for each edge u, v p do 6: b(u, v) b(u, v) + c(p); b(v, u) b(u, v); 7: c(u, v) c(u, v) c(p); 8: if c(u, v) = 0 then 9: remove u, v from M; 10: cleanup of M; 11: if indegree(v) = 0 then 12: CleanForward(v, M); 13: until indegree(t) = 0: Algorithm 5 CleanForward(u, M) Pre-condition: indegree(u) = 0. 1: for each v such that u, v M do 2: remove u, v from M; 3: if (indegree(v) = 0) then 4: CleanForward(v, M); Post-condition: Let x be any vertex such that at the start of CleanForward all paths back from x in M end at u. Then all edges going out of x have been removed. 5 Analysis of the running time 5