^~ Of r^'y :4Mii ALFRED P. WORKING PAPER SLOAN SCHOOL OF MANAGEMENT IMPROVED TIME BOUNDS FOR THE MAXIMUM FLOW PROBLEM R. K. J. B. Ahuja Orlin R. E. Tarjan Sloan W.P. No. 1966-87 December 1987 MASSACHUSETTS INSTITUTE OF TECHNOLOGY 50 MEMORIAL DRIVE CAMBRIDGE, MASSACHUSETTS 02139 I L: IMPROVED TIME BOUNDS FOR THE MAXIMUM FLOW PROBLEM R. K. }. B. Ahuja Orlin R. E. Tarjan Sloan W.P. No. 1966-87 December 1987 ^EB 8 1988 !l''i~n Improved Time Bounds for the Maximum Flow Problem Ravindra K. Ahuja ' James B. Orlin •a Robert E. Tarjan ABSTRACT Recently, Goldberg proposed a flow problem. The approach time on n-vertex networks. new approach maximum network to the yields a very simple algorithm running in O(n^) Incorporation of the djTiamic tree data structure of more complicated algorithm with Sleator and Tarjan yields a a running time of 0(rmi log {n} Im)) on m-edge networks. Ahuja and Orlin developed a variant of Goldberg's algorithm that uses scaling and runs in 0{nm + n? works with integer edge capacities bounded by U. In modification 0{ntn + n 7 of the lo"C/ ). Ahuja-Orlin We show with algorithm that the use this a logC/) time paper we running of dvnamic trees in this on net- obtain a time of algorithm loglogt/ reduces the time bound to 0{,nm log( that the ^ m combined use of scaling and dynamic by using + 2)). This result demonstrates loglogf/ trees results in speed not obtained either technique alone. MA 02139. Research parliaUy supported by a Presidential Young InNSF, Contract 8451517 ECS, and grams from Analog Devices, Apple Computer Inc., and Sloan School of Management, M.I.T., Cambridge, vestigator Fellowship from the I^rime On Computer. leave from the Indian Institute of Technology, Kanpur, India. DepL tially of C. S., Princeton University, Princeton, supported by NSF NJ 08544 and AT&T Bell Labs, Murray Hill, NJ 07974. Research Grant DCR-8605962 and Office of Naval Research Contract N00014.87-K-0467. par- Improved Time Bounds for the Maximum Flow Problem Ravindra K. Ahuja 2 1 ' James B. Orlin Robert E. Tarjan 1. Introduction We We The graph set E. a source G is tices, the base is is iflow network if it flow problem [5,6,12,14,19]. (V,E) be a directed graph with vertex set symmetric, i.e. number of (v.h) e E iff edges, and the we assume m edge capacities are integral. (w,v) € E. maximum > n-\ and U V and has two distinct distinguished vertices, a sink s and and a non-negative real-valued capacity u(v,h) on each edge (v,^) e E. t, time bounds, that all G maximum network G= formulate the problem as follows. Let edge that consider algorithms for the classical We denote by n,m, and U the We assume number of ver- edge capacity, respectively. For ease in stating >4. Bounds containing U are subject to the assumption All logarithms in the paper are base two unless an explicit given. A flcnv / on a network G is / on a real-valued function the edges satisfying the following constraints: /(v,w) < u(v,w) for /(v,mO = -/(w, v) for S v:(v,H') /(v,w) = all all for all (v.w) e (v.w) g w E E (capacity constraint), (1) (antisymmetrj' constraint), (2) e V'-{j,r} (conservation constraint). (3) g£ Sloan School of Managemeni, M.I.T., Cambridge, vestigator Fellowship from the MA 02139. Research partially supported by a Presidential Young In- NSF, Contraa 8451517 ECS, and grants from Analog Devices, Apple Computer Inc., and Prime Computer. ' On ^ DepL of C. leave from the Indian Institute of Technology, Kanpur, India. S., Princeton University. Princeton, N'J 08544 and tjaUy supported by NSF Grant DCR-8605962 AT&T Bell Labs. Murray Hill, N7 07974 Research and Office of Naval Research Contract N0O014-87-K-O467. par- — The value /I of a flow I /is Ihc net flow into the sink: Z 1/1= /(v.f). v:(v,()e£ A maximum flow maximum a flow of maximum value. The maximum flow problem is that of finding a flow in a given network. We Remark. is assume that all edge capacities are path of infinite-capacity edges from sum of the finite capacities, .s to f exists, If finite. some edge D a long and rich historj', and a series of faster and faster The previously algorithms for the problem have been developed. (See [10] for a brief survey.) known fastest 0{nm algorithms are those of Goldberg and Tarjan [8,10], with a running time of log (n^/m)), and that of Ahuja and Oriin Both of these algorithms we no then each infinite capacity can be replaced by the without affecting the problem. The maximum flow problem has capacities are infinite but [2], with a running time of method proposed by Goldberg are refinements of a generic shall call the preflow algorithm. 0{nm + For networks with m = n(«^), n'^^ [8], the Goldberg-Tarjan \ogU). which bound is O(n^), which matches the bound of several earlier algorithms [11,13,15,20]. For networks with m = 0(n'^~'-) the for bound of namely unless U- some constant e > 0, the Goldberg-Tarjan bound the earlier Sleator-Tarjan algorithm [16,17]. 0{n'^) for m =0(n) or m some constant k, Under a sophisticated data structure, the and Tarjan [18,19], whereas the alone. to We 0(nm + first n"^ results in a log/i), which matches the similarity assumption [7], the Goldberg-Tarjan bound = Q(n'). The former uses strate that the use 0(nm bound beats the Ahuja-Orlin The Goldberg-Tarjan and Ahuja-Orlin algorithms obtain techniques. is latter their dynamic Our main purpose uses scaling. speed from two different tree structure of Sleator in this paper is to demon- of both techniques results in efficiency not obtained by using either technique modify the Ahuja-Oriin algorithm ^ loglogt/ ). Then we show running time of 0(nm log( to obtain a small that the use of — m — ; r 77 dynamic improvement in running time, trees in the modified algorithm +2)). Under the similarity assumption, this loglogf/ bound with is better than m =0(n) and all previously U = 0(n*) for known bounds some constant for the k, the maximum bound is flow problem. For networks 0(nm loglogn), which beats both the Goldberg-Tarjan bound and the original Ahuja-Oriin bound by a factor of logn/loglogn. Moreover, the bound rapidly approaches 0{nm) as the graph density m/n increases. 3- Our paper consists of four sections in addition to this introduction. we review the preflow algorithm. In Section 3 analyze our improvement of method of Section 2. it. In Section 4 In Section 2 we review the Ahuja-Oriin algorithm and descril>e and we combine dynamic the use of 3 and analyze the resulting algorithm. Section 5 contains some trees with the final remarks. The Preflow Algorithm method of Ford and Fulkerson In contrast to the classical augmenting path flow along an entire path from to once, the preflow method at : The key concept underlying at a time. A preflo\^' f IS [11]. .s For any vertex m, tion of (3). let on moves flow along constraint is edge the edges satisfying constants (1), (2), and a relaxa- the ^owexce^^ of ^ w be e(w) = /(v.w). e E the following: e(w) > We a single by Karsanov is v:(v,>v) The required which moves that of a preflow, introduced the algorithm a real-valued function [6], call a vertex v active if for all v^ t w e V-{s} (nonnegativity constraint). and e(v) > 0. Observe (4) that the nonnegativity constraint implies \ha.te{s)<0. The «/{v,h) = capacity residual u(v,w}-f(v,w). An of edge edge an is (v.w) saturated if with Uy<v,w) respect = a preflow and a / preflow is and unsaturated otherwise. (The capacity constraint implies that any unsaturated edge (v,w') has «/(v,w) The preflow algorithm maintains to > 0.) moves flow from active vertices through unsaturated edges toward the sink, along paths estimated to contain as few edges as possible. Excess flow that cannot be moved to the sink test paths. is Eventually the preflow becomes a flow, which As an to the nonnegative integers such that d{s) every unsaturated edge (v,m). A d(v) < min {dj{v,s) where df{v,w) is a maximum + n,dj{v,t)), unsaturated and d{v) = n, proof by induction shows is the flow. = d{w) + 1. d(t) = that, 0, flow /. We is a function and d(v) < d(w) + 1 d for for any valid labeling d, minimum number w consisting of edges unsaturated with respect to the (v,w) is estimate of path lengths, the algorithm uses a valid labeling, which from the vertices V to returned to the source, also along estimated shor- call of edges on a path from an edge (v,w) eligible if 4- The algorithm begins with an preflow/and valid labeling d defined initial as follows: f w(v,h) if V /(v.w) =\ -mCw.v) w = 5, if if V d(v) The algorithm = min \d^ {\,s) consists of repeating the following = s, 7i + 5 and w * 5, /i,d/v,f)}. two steps, in any order, until no vertex is ac- tive: push (v,w). Applicability: Vertex v is active and edge (v.w) Action: Increase /(v.w) by min {e(v),uy<v,H')). is eligible. The push is saturating if (v.w) is saturated after the push and nonsaturating otherwise. relabel (v). Applicability: Vertex v is Action: Replace d{v) by When active and no edge min [d(w) +1 the algorithm temiinates,/is a I (v,>v) is eligible. (v,w) maximum is unsaturated}. flow. Goldberg and Tarjan derived the fol- lowing bounds on the number of steps required by the algorithm: Lemma The 2.1 [10]. total Lemma Relabeling a vertex v number of relabelings 2.2 [10]. There arc at strictly increases d{\). No vertex label exceeds 2n-\. at most 0{n^m) nonsaturating 0{n^). is most 0{nm) saturating pushes and pushes. Efficient implementations of the and relabeling steps to perform. vertex, construct a (fixed) the first on the list, list above algorithm require a mechanism for selecting pushing Goldberg and Tarjan proposed the following method. For each A{\') of the as the current edges out of edge out of v. To v. Designate one of these edges, initially execute the algorithm, repeat the following 5- step until there no active vertices: push/relabel (v). Applicability: Vertex v is active. Action: If the current edge (v.w) of v is not the last edge on A{v), make With 0{n^m) time bound ing push. This gives an Making steps. the implementation, the algorithm runs in this first edge onA(v) the current one. 0(nm) time plus 0(1) time per nonsaturat- for any order of selecting vertices for push/relabel the algorithm faster requires reducing the time spent number of such pushes can be reduced by Goldberg and Tarjan showed that FIFO on nonsaturating pushes. The selecting vertices for push/relabel steps carefully. selection [3] showed tion (always pushing flow from a vertex with highest label) reduces the Ahuja and Orlin proposed to 0{n''m^'"). number active, first selected) reduces the (first of nonsaturating pushes to 0{rr'). Cheriyan and Maheshwari pushes if (v,iv) the next edge after (v.w) the current one. Other- make wise, perform relabel (v) and perform pay/2(v,w). Otherwise, is eligible, that highest label selec- number of nonsaturating which we discuss a third selection rule, in the next section. 3. The Scaling Preflow Algorithm The algorithm, imum behind the Ahuja-Orlin algorithm, henceforth called the scaling preflow intuitive idea is to move large amounts of flow when possible. The same idea capacity augmenting path method of rithm of Gabow [7]. One way from a vertex of large excess reduce the maximum Making For tor method [4] to apply this idea to the preflow algorithm is to to a vertex of smaU k>2. A As smallest vertex v is excess, or to the sink. The always push flow effect of this is to at a rapid rate. precise requires specifying said to have large excess if its the algorithm proceeds, k remains fixed, but power of k such behind the max- and the capacity scaling algo- when an excess purpose the scaling preflow algorithm uses an excess bound this wise. this excess Edmonds and Karp is that A>U. is A and large and when small. an integer scaling fac- excess exceeds A/k and small excess other- A periodically decreases. Initially, The algorithm maintains the invariant that e(v) <A A is for every active vertex v. This requires changing the pushing step to the following. push (v,w). Applicability: Vertex v Action: Uw^^t, is active and edge (v,w) increase /(v,w) by min is eligible. {e(v),Uf (v,w), A-e(w)). Otherwise (w the = t). 6- incrcasc/(v,w) by min The algorithm A stant. { e(v),uy (v,w)}. number of scaling phases, during each of which A remains con- consists of a phase consists of repeating push/relabel steps, using the following selection A by no active vertex has large excess, and then replacing A/k. Large excess, smallest label selection: Apply a push/relabel step among such choose one of smallest vertices, edge capacities are If the phases: after [log^ + ^7 integers, A < phases, ij 1, to a vertex v number of nonsaturating pushes. of large excess; label. algorithm terminates after tlie which implies We repeat the most [log^ at U+ that /is a flow, since the algorithm Ahuja and Orlin derived a bound of 0(kn^ tains integrality of excesses. rule, until analysis here, since log;^ U) on ij main- the total provides motivation for our it modification of the algorithm. Lemma The 3.1 [2]. 0{kn'^ Gog* U+ total number of nonsaturating pushes preflow algorithm is 1)). 0= ^ Consider the function Proof. in the scaling We e{v) d{\-)IA.. call <t> the potential of the current V active preflow / and labeling Q<^<2n~ 0<e(v)/A< O by at least w with d(yv) ing a relabeling or = \lk, since the 2/z^. [log;: U + Llog;t t/ -(- , when A changes. A value of When A times. \} 2j O Q<d{\)<2n and . The and the Choosing )t changes, Thus total O is for every active vertex v, A orw = t. The value of <t> can relabeling of a vertex v increases A due the total increase in is at by at most 2n'^. is at at is total is at most at most 2«' most k times the sum of the most 2kn^ [^og* be constant independent of n gives a most the amount This happens over the entire algorithm number of nonsaturating pushes O. This k, to at <I> increase only dur- over the entire algorithm, to relabelings, ^ nonsaturating push- from a vertex v with excess more than Alk increases by a factor of total increase in to push d(v) -1 and e(w)< A/k d{v) increases. Thus the total increase in most 1 throughout the algorithm. Every pushing step decreases O. ing step decreases to a vertex Since d. initial ^ + 3j D . time bound of Oinm + n'^ \ogU) for the scaling preflow algorithm, given an efficient implementation of the vertex selection rule. One way to containing implement the all by vertex label, each set large excess vertices with the corresponding label, and to maintain a pointer to the nonempty set Oimn \ogU). -(-«' rule is to maintain an array of sets indexed of smallest index. The total time needed to maintain this structure is -7 Remark. The bound for the scaling preflow algorithm can be improved terms of a different parameter. Let U* in =4 + '^ O + (nni can pushes turating be reduced logU*). This improvement n'^ O to is and {n^ iogU*) the to / be the first phase such that A<U* and including the change from phase . / Then - 1 time overall The argument [4]. algorithm maintains the invariant that the total excess on active vertices phase bound on nonsa- the improvement Aho and Li similar to the measured it is E minimum-cost flow algorithm of Edmonds and Karp the Then u {s,v)/n. v:(i,v)€ slightly if obtained for The as follows. most nU' . ^ InlT'^ = O(n^). most n is at i is at to Let O due to phase changes up the total increase in to phase is [1] bound The 7=0 due total increase in to later Having described phase changes is O («^ logt/*). the Ahuja-Orlin algorithm, we D consider the question of whether ning time can be improved by reducing the number of nonsaturating pushes. Lemma bounds the number of nonsamrating pushes by estimating the 3.1 potential O. due to Observe that there is an imbalance in phase changes, whereas only 0(n^) is due to relabelings. mate by decreasing the contribution of the phase changes, tion of the relabelings. We Making 0{n^ this estimate: log^ Our plan at the cost its run- The proof of total increase in the U) of is to the increase improve is this esti- of increasing the contribu- plan work requires changing the algorithm. this use a larger scale factor and a slightly more elaborate method of vertex selection. push flow from a vertex of large excess, choosing among such vertices one with highest We label. This vertex selection rule does not guarantee that a nonsaturating push moves enough flow, and we need a stack-based implementation to ensure this. tices, with the property that of At the beginning of V. if w is just on top of v The algorithm maintains on the a stack 5 of ver- stack, then (v,wO is the current a scaling phase, the stack is initialized to be empty. The phase consists of repeating the following step until no vertex has large excess, and then replacing stack push/relabel: If S S of Apply the appropriate one of the following three V. Case definitely 1 : (v,w) this section). while S Case is nonempty. Let is eligible. If the is v be the top vertex A/k. on 5 and (v,w) the current edge out cases: Perform push (v,w) (modified as described push nonempty and 2: (v.w) A by empty, push onto 5 any large-excess active vertex of largest label. is Now is edge out is its nonsaturating and e(v) top vertex has small excess, not eligible and out of V by the next edge on > A is (v). not last on A (v). 0, push pop w at the onto S. beginning of Otherwise, S. Replace (v,w) as the current edge -8- Case and 3: (v,w) is not eligible is last (v.w) as the current edge out of v by the its A on (v). first Relabel v and pop from it edge on A(v). While S is Replace S. nonempty and top vertex has small excess, pop S. Observe that the stack push/relabel step is augmented with some just a push/relabel step manipulation of the stacks. Before carrying out a detailed analysis of Every push made by the algorithm results in tion of move we make A from a vertex of large excess. is several observations. push along an edge (v.w) one of three events: saturation of (v.w), conversion of v into an inactive vertex, or addi- w to S with an excess of A. In the third case (and only in the third case), the push may zero flow. Lemma 3.2. algorithm is The Lemma 0{nm + kn^ + 3.1, but Y, number of nonsaturating pushes made by total To bound Proof. <S?= this algorithm, n^ Oogt U+ the stack-based scaling prcfiow 1)). number of nonsaturating pushes, we use an argument the with two potentials instead of one. The By ^(^) '^(v)/A. the analysis in the proof of first Lemma potential that of is 3.1, ever>' proof of like the Lemma push decreases <i>, 3.1, and V active O over all the total increase in or decreases the size of ing flow from V to unstacked until it w is S. phases (9(n^ log^U). Every nonsaturating push either increases is Consider a nonsaturating push and stacking w. relabeled or until When w its w to the relabeling of w after w is k> 2, there are a total decreases in stacked, excess decreases to charge the push from v to caused by pushes from is that increases the size h', it at has an excess of A. it is It cannot be most A/k. In the former case we in the latter, to the at least stacked and before of S, say by push- unstacked. Since 1-1 Ik decrease in 1 -1 /i > 1 /2 for <i> all of O(n^) pushes charged to relabelings and Oin^ \ogkU) pushes charged to (t>. We now count the nonsaturating pushes that reduce the size of pushes that begin with more than one vertex 5 ceded by a nonsaturating push is 0{n^ that adds a vertex to 5, logytt/), since The number of such S. each such push must be pre- and the number of these is 0{n'^ logit/) by the above argument. The remaining pushes end with none on 5. We decrease in 0, namely that call \/k\ are those that begin with such pushes emptying. thus using 0(^71^ \ogkU) on their number. potential, must be counted We O to An emptying one vertex on S and push can cause a rather small bound such pushes only gives a bound of count emptying pushes more carefully by using a second ^2- The definition of O2 involves two parameters, an integer / and a set P. The value of / is equal to the empty during minimum with label equal to The that Observe the current phase. The creasing during a phase. Observe of 2« and the smallest label of a vertex added to S while S was P P = / the beginning of a phase and 2/i at consists of all vertices with label greater than and / is / all nonin- vertices from which an emptying push has been made during the current phase. empty is definition of / set that P never loses the beginning of a phase and at a vertex during a phase. <I>2 is Z <E>2= + e(v) (rf(v) -/ 1)/A. (If/' = 0, <I>2=0.) ve P :e{v)>0 Observe by at least hence so 1 is The number of vertices added Ik. the number of emptying pushes To bound the total increase in to P < O2 < 2«^. Any emptying push that P to ^2 in are due is at that decrease to relabelings O2 by fact that the relabeling There are due at may add v to P. most 2n decreases to decreases in The total is at / in Thus / 4kn^ + 2n^llogi,U + As most 2«^ [logt O2 in the is initially by at least 1/^, and to decreases { 5 when S of doubly 1,2,. ...2/1-1 }. We in P has that decrease zero. Thus is is 0(nm). The only empty. For linked hsts the (A vertex added A <I>2) relabeling of one" accounts at for the growth of to the by one adds <[>2 all most n/k to phases. by the total at least 1//: is at most k times the number of such pushes purpose, this list(r) = to is at most perform saturating significant remaining issue {i this structure requires (9(1) The pointer can only change in label) or due /. we bound small excess. Thus the total increase in /k over Ij / phases, and /k. we e N: is to a how e(i)>A/k and d(i) = at most pointer needs to be incremented or decremented is choose for r} which each list (r) is time per push operation plus time to main- increase due to a relabeling (by at most the phase change (by to maintain a data structure consisting of also maintain a pointer to indicate the largest index r for non-empty. Maintaining tain the pointer. + f/ decrease in 1 most 4n^ Goldberg -Taij an and Ahuja-Oriin algorithms, the time vertices to add to € at least all O2 . \\ pushes and relabeling operations collection A or decreases by relabelings contribute at per phase. number of emptying pushes total increase in (i>2, since r <I>2 P over \j in d(v) plus one; the "plus most the increase at O2, since when the decrease occurs every vertex in a <I>2 U+ because of an emptying push has zero excess and hence adds nothing to a vertex v increases <I>2 most n [logi do not decrease that number of emptying pushes O2. Increases either adds a vertex to 2n). Oin'^ amount of ConsequenUy, the number of times the + nQogk U + 1)). The overall running 10 time of the algorithm thus is 0(nm + kn^ + n^ilog/^ U + l)). Choosing k=l log t//log log Ul gives the following result: Theorem The stack-based 3.3. 0(nm + n^ ^°f^,, )time. , log Remark. \ogU = 2 until the switch occurs, 4. we O to U replaced O 6'*) is \ogU' /log A increase which A > These phases account for only as above with to ^ =1" and then switch the initial phases (those in is improved be (nw + n' logt/*/loglogf/*), We where use a scaling factor of E A<U' When rithm. can " {s,v)/n. The algorithm niust be changed slightly. Y, v:(j,v) e k bound This U' =4 + scaling preflow algorithm, with an appropriate choice of ^, runs in (if the necessary) to be a power of same as that in the (n^) nonsaturating pushes. by U' . for the remainder of the algo- logL'*"j The The k. remark following analysis of Lemma 3.1. analysis of the remaining phases D Use of Dynamic Trees The approach taken in Section 3 tices for push/relabel steps carefully. number of pushes by choosing was to reduce the total An orthogonal approach is to ver- reduce the total lime of the pushes without necessarily reducing their number. This can be done by using the dynamic tree data structure of Slcator and Tarjan [18,19]. algorithm with a bound of p> from 0(p) to 0(nm log(-^ mn prove a general theorem to of the preflow algorithm mn on -i- 1)) the total conjecture that, given a version of the preflow number of pushes, by using dynamic this effect, we have We we have been considered. the running time can be reduced Although we do not know trees. applies the to o(^iog( scaling log iogU m :'°f,, The dynamic in this case is As an example, preflow 0{n^). In algorithm the 0(nm log {n^ Im)) time bound this section of Section 3, we shall resulting show The data find root (v): time bound same idea bound of ^2)). tree data structure allows the directed from child to parent. itself. rule; the that the a in maintenance of a collection of vertex-disjoint rooted trees, each edge of which has an associated real value. Each tree edge of to able to obtain such a result for each version of Goldberg and Tarjan results from using d>Tiamic trees with the FIFO selection on the number of pushes how We is regarded as being regard every vertex as being both an ancestor and a descendant structure supports the following seven operations: Find and return the root of the trce containing vertex v. 11 find size (v): Find and retuna the number of vertices in the tree containing vertex find value (v): Find and return the value of the the value returned find min (v): edge leaving tree v. If v is a tree root, is infinity. w of v with minimum find choose the vertex w closest to the tree root. Find and return the ancestor case of a change value Add (v,x): tie, real v. number x value (w). In of every edge along the path from v to to the value find root (v). Combine link (v,w,xy. the trees containing v and giving the edge (v,w) the value w are in the Break the cut (v): to same sequence of (9(/log (2 + 1)) time / if tree containing v into two trees by deleting the edge joining v if v is This operation a tree root. tree operations, starting with an initial collection of singleton trees, takes if z is maximum the tree size [18,19]. In our application, the dynamic tree edges form a subset of the current edges out of vertices. dynamic Every dynamic tree A on size of a an eligible edge; is the maximum dynamic tree. Two ability. excess at no active residual capacity. tree push/ relabel (v): active. the The the preflow algorithm, called the tree parameters govern the behavior of the algorithm, a z, 1 < z < n, on the maximum consists of beginning with an initial preflow vertices: is is its all entire path at once, rather than an active vertex, and a bound The algorithm Applicability: Vertex v value moved along an labeling d, and with every vertex as a one-vertex until there are its The following version of at a time. preflow algorithm, uses this bound edge tree data structure allows flow to be along a single edge v and tree or if v is not a tree root. parent; return the value of the deleted edge. its parent of v and This operation does nothing x. breaks no edge and returns infinity A w by making w the dynamic tree, /and a valid and repeating the following step 12 Action: Let (v.w) be the current edge out of Apply v. one of the the appropriate following cases: Case J: (v,w) is eligible. and 5 = eifx = 5 = min r, x=find Let A (e, root (w), e -e(x)} x ^ if = min {e(v), Uf (v.w), find Send 5 t. from V to X. The tree push is saturating if 5 push) and nonsaturating otherwise. push), and find size (v) Case 2; (v,w) = 3: (v,w) is push is called a tree push min Uf (v,w),find is x by (v)} (before the nonsaturating, e(v) perform link (v,w,Uf (v,h')). = (after the Otherwise, while and not not eligible and current edge out of v by the last on A(v). Replace (v.w) last on A(v). as the current edge A (v). out of V by the next edge on Case z, ( to perform cut (find min (w)). not eligible is If the tree + find size (w) < find value (find min (w)) = min from v units of flow increasing /(v.w) by 5 and performing change value (h',-5). This min (w)), first is Relabel edge onA(v). For every tree Replace (v,w) as the v. edge (}',v) perform cut(y). This algorithm stores flow in two different ways: explicitly for edges that are not d>'namic tree edges and implicitly in the dynamic tree data structure for After each cut, the flow on the edge cut must be restored to when the algorithm terminates, the correct flow value its edges that are dynamic tree edges. correct current value. on each remaining In addition, edge must be com- tree puted. For edges cut during the computation, the desired flow values are easily computed, since the current residual capacity of an The algorithm just presented Goldberg and Taijan [9,10]. is 0(nm tree log (z pushes The in turn [10]. + is 1)) The plus tree size total OOog returned by the cut operation. Computing most nfind value operations. a generic, modified version of the Goldberg and Tarjan gives the following 4.1 at is dynamic tree algorithm of maintains the following invariants: every active vertex It no excess exceeds A; no Lemma that is cut on termination can be done using correct flows root; edge (z exceeds z; every tree edge eligible. The a tree analysis of result: by time required + per tree push. 1)) is is the dynamic tree The number of prcflow links, cuts, algorithm is and saturating 0(nm). efficiency of the algorithm depends on the depends on how number of nonsaturating tree push/relabel steps are selected. We shall show -I analogous to that used in Section 3 results in a bound of 0(nm + kn^ + — tree pushes, that a selection order fl" z which (logi t/ + 1 )) on the -13- number of nonsaturating of Oinm log We — — m — f -7 log log (7 + ; ( A In addition to parameters maximum (the that A> and A maximum z (the this a total time bound 2. active vertex v dynamic tree is tree size), the algorithm Whereas = decreases. Initially S and (J) and k remain fixed z A is the smallest integer said to have large excess if e(v) is said to be large if The tree/scalmg algorithm otherwise. srrujll An U. A small excess otherwise. excess) and the scaling factor, and a stack S. k, From the scaling factor. by an appropriate choice of k and 2)) follows throughout the running of the algorithm, power of k such is version of the pre flow algorithm the tree/scaling prefiow algorithm. call the resulting uses a third parameter where k tree pushes, consists > A/k and contains more than z/2 venices it of repeatedly applying the tree push/relabel step to the top vertex on S, while manipulating S according to the following rules: Rule 1 . If S is tices are roots empty, add of large S any to add trees, active vertex that to vertices are roots of large trees and S a large-excess active vertex have small excess, replace all minates when A < Rule After a tree push from a vertex 2. push X onto Rule 3. If all active ver- of largest label. A by If all active Alk. (The algorithm ter- 1 .) Otherwise, while S S. the root of a small tree. is v to a vertex x, if the nonempty and is After relabeling a vertex, pop it from S, its push is > 0, nonempty or its nonsaturating and e{\) top vertex has small excess, pop and continue pop S to until it is S. top vertex has large excess. Every tree push made by the tree/scaling algorithm a small tree or has large excess. Rules 1-3 tree 0{n} + is nlogk, {U -^ As discussed \)) plus (9( 1 ) from is in Section 3, the a vertex that is either the root of time necessary for implementing per tree push, which is dominated by the bound on pushes derived below. — 2 Lemma 4.2. The tree/scaling algonihm makes Oinm -1- kn^ + (log^ U -t- 1)) nonsaturating tree pushes. The argument Proof. defined by 0= ^ V and changes after a analogous We e{v) d{v)! A. 10 the proof of have 0<<t><^^. Lemma 3.2. Increases in Let the potential O are due O be to relabelings acuve in the value change is of A. The in the value of A, <t> total increase in < 2n- :, <i> due to relabelings is Oin'^). Immediately because every active vertex must be the root of a large tree, and only Iniz large trees can coexist. Thus the total increase in O caused by changes 14- — 2 inAisOC Gogi + f/ l)). z Consider nonsaturating tex added least 1-1 We to S. /it is O caused by pushes from x before x decrease in n' begin with 0(n^ — -^ 0(n' thus pushes that add a vertex to (logic ^' h + Similarly, the !))• let U+ is popped. The x be the ver- at one least pushes tree from vertex at number of such total number of nonsaturating more than one vertex on S and pop (logt For such a push, 5. charge the push either to the relabeling of x that pops x from S or to the -> pushes tree S that also is \)). z The on 5 and the only vertex An emptying them push from We call after the push. push from a vertex a v that is such a push an emptying push. To count emptying a vertex v reduces e(v) to zero. trees is and those from roots of large we pushes, divide trees. charge an emptying push from the root v of a small tree to the event that either created made the tree or last active, popped from 5 is from roots of small into those We we must count kind of nonsaturating tree push that last we charge the push most one push, and there If the tree whichever occurred v active, Each to the link or cut that created the tree. 0{nm) are was created before v links became and cuts, was created If the tree first. link or cut became after v is charged to at which gives an 0{nm) bound on such pushes. active, then v became active as a result of a sauirating push, of which there are 0(nm), or as a result of a nonsaturating push from the root of a large tree. to We have already counted the number of such pushes that are nonemptying. Thus count emptying pushes from the roots of large We integer / set P, as in the proof of Lemma 3.2. ^2 To (As in Section 3, which A stays constant.) The with label equal to definition of Oj / The value of / is the minimum X P Tlie total increase in due consists of all an of 2n and the was empty dunng the maximal period of time during vertices with label greater than / and all vertices is v € is P define a phase to consist of a to define from which an emptying push has been made during the current phase. The ^2= tion set we we need define Ot, smallest label of a large-excess root of a large tree added to S while S current phase. suffices trees. count such pushes using a second potential and a it to relabelings. e(v)(d{v)-l + l)/A. (If P =0,^2=0) eiv) > O; over all The 0{ phases — kz Gog* is 0(n' U+ 1)) -t- — Oog^ contribution U+ is 1)). due The 0{n') contribu- to decreases in /. A 15- decrease in / by one causes an 0( — ) increase in O2, since, just after such a decrease in occurs, / kz P every vertex in has level greater than /, P and every active vertex in has small excess and the is root of a large tree. Every emptying push from the root of <^2' which can happen Oikn^ + U+ can happen OinQog^ Combining Remark. A — U+ Gog* Since ])) times. a large tree causes either a decrease < 2 \)) at least 1/^ in times, or an addition of a vertex to P, which a choice of —+ =!" /t preflow algorithm runs in 0{nm\oz and 2] ^ z Lemmas — 4.1 + ( " By on 1)) the argument using only = min {[ n Proof. the former. number of nonsa- <I>, analogous to the D 3.1. With 4.3. + (log2 t/ turating tree pushes can be obtained with a simpler Theorem dominated by *" kn 1 proof of Lemma is D weaker bound of 0(nm + kn' + slightly bound n, the latter our estimates gives the lemma. all of — m log^ t/ + ,n) the tree/scaling l] 2)) time. mlog \ogU and running the 4.2, of time algorithm the is -> OCfrini +/tn- + Gogi + l))log(z + f.' This D). O(Aimlogn) is if z =[ z On the other hand, the algorithm if z again is Case = 0(nm \ogU 1: the ai I compulation logn). We complete is after — m + logt t/ < l] n. one phase, and the running time of consider two cases. \og\ogU > ml\n. Then ^ log( + 2) = Q.(\ogn), and the mloglogu theorem true. is logU log \ogi' < Case 2: log2[/ = 0{m). Let / m / \n . Then log2t//log:log;t/ < m^"*, which implies — ^2 us estimate the quantity = 0{nm). n (\ogt,U + \) — U + \)< On Gog^ hand, other the U + \). If r if z = n, this =\ — m quantity log^ t/ + is l] , ^2 (log;, 2 run. follows Ii that the running time of the algorithm is z — nl02tL' 0{nm\ogiz + ^ ^^— \)) = 0(nm\0'ci "log* log ( m + 2) - 0(log m +2)). ^locL'' ( r m loglogc/ ,, + 2)). It We remains have log* U prove to = logU I log that m (— n + 2). —— 16 - Again the proof divides into Casel.l: \ogU >{— two cases: + 2)\ Then loglogt/>4, log —r~77 + mlog then log Case log which (—7 > (— log + (- implies log log logt-^ — < — log \ogU. > log logt/ - log log \ogU - log (m/n) > \ogU < + ^ 2) ( 2) < log Qog^ + —n + = 2)^. = 0(log( 2) In this case log ^ log + ( mlog(— + Also, 2) -^^^ m —+ log ( 2)), as desired. —n + —^— - ( But '^ =" \ogU log \ogU < 4 < log Hence log logL^. 4 + m > log(m/n). 2) n logt/ 2.2: ( 2) log logf/ -J- 4 n m\og\ogU which implies 2), + = OC 2) f-— + — m — ; log logL 2) as desired. Thus in all cases the algorithm runs in the claimed time bound. D 1 Remark. The bound in the theorem can be improved gously to the improvements in the bounds of Section of the algorithms of Section 3 with k A< T !* + ( m obtain this improvement, U' and then switch , 2), analo- log logL' we run one to the d>Tiamic tree algo- Remarks The is 2 until To log n rithm, 5. = 3. 0{nm to scaling preflow algorithm of Section 3 not only has a We likely to be very efficient in practice. this is true. The algorithm of Section 4 huge networks there some chance is The two obvious open bound for the maximum cost flow problem. It is is perhaps mainly of theoretical interest, although for of dynamic trees theoretical questions are is not unreasonable to hope for a bound of capacities arc not too large, ^= i.e. 0{nm) would seem to require major new ideas. 0(nm) 0(nm) for the in the time minimum maximum flow for graphs that are not too —— = Oimin). loglogf/ better than be practical. possible and whether our ideas extend to the I02L' whose edge may whether funher improvement problem; note that the bounds of Theorems 3.3 and 4.3 are sparse and theoretical time bound, but intend to conduct experiments to detenmine whether that the use flow problem good Obtaining a bound 2), 17 As a partial answer to the secxind question, Oirvn loglog cost, U assuming additional ones. log (nC)) for the all It edge costs are will minimum integral. we have been able to obtain a time cost flow problem, where C is the bound of maximum edge This result uses ideas in the present paper and some appear in a future paper. -18- 6. Acknowledgements We thank 7. Andrew Goldberg for inspiring ideas and stimulating conversations. References [I] A.V. Aho and and minimum D. Lee, "Efficient algorithms for constructing testing flows," unpublished manuscript, AT&T sets, covering paths, Bell Laboratories, Murray Hill, NJ, 1987. [2] R.K. Ahuja and J.B. Orlin. "A fast and simple algorithm for the maximum flow prob- lem." Technical Report 1905-87. Sloan School of Management, M.LT., 1987. [3] J. Cheriyan and S.N. Maheshwari. "Analysis of preflow push algorithms for ma.ximum network flow." Department of Computer Science and Engineering, Indian Instimte of New Technology, [4] J. Delhi. India. 1987. Edmonds and R.M. Karp. "Theoretical improvements in algorithmic efficiency for net- work flow problems." Journal of ihe ACM. 19:248-264, 1972. Even. Graph Algorithms. Computer Science Press, Potomac, [5] S. [6) R.L. Ford, Flows and D.R. Fulkerson. Jr. in MD, 1979. Networks. Princeton University Press, Princeton, NJ, 1962. [7] H.N. Gabow. "Scaling algonihms for network problems." J. of Comp and Sys Sci.. 31:148-168, 1985. [8] A.V. Goldberg. "Efficient Graph Algorithms for Sequential and Parallel Computers." Ph.D. Thesis, M.I.T., 1987. [9] A.V. Goldberg. "A New Max-now M T Laboratory for Computer Science. [10] Mach [II] [12] , , 1985. approach to the maximum flow problem." In on Theory of Computing, pages 136-146, 1986; J Assoc. Comput. to appear. A.V. Karzanov. "Determining preflows." Soviet Math Dokl E.L. Lawler. Winston, [13] ACM Symp I "A new A.V. Goldberg and R.E. Tarjan Proc. 18th Algorithm." Technical Report MIT/LCS/TM-291, New . L*^ the maximal flow NY, a network by the method of 4.W-437. 1974. Combinatorial Opumizatum York, in Sec^orks and Matroids Holt, Reinhart. and 1976. V.M. Malhotra. M. Pramodh Kumar, and S.N. Mahcshwan. "An O(IV'I^) algorithm for -19 finding [14] maximum flows in networks." Inform. Process. Leu., 7:277-278, 1978. C.H. Papadimilriou and K. plexity. Prentice-haU, [15] Steiglitz. Englewood Y. Shiloach and U. Vishkin. Combinatorial Optimization: Algorithms and Com- Cliffs, "An 0{n^ NJ, 1982. logn) parallel max-flow algorithm." Journal of Algorithms, y.n%-U(>, 1982. [16] D.D. Sleator. port [17] "An 0{nm \ogn) Algorithm for ST AN-CS-80-831, Computer D.D. Sleator and R.E. Tarjan. Maximum Network Flow." Technical Re- "A Science Department, Stanford University, 1980. data structure for dynamic trees." J. Comput. System Sci, 26:362-391, 1983. [18] D.D. Sleator and R.E. Tarjan. "Self-adjusting binar>- search trees." J. Assoc. Comput. Mach. 32:652-686, 1985. [19] R.E. Tarjan. Data Structures and Network Algorithms. Society plied Mathematics, Philadelphia, [20] R.E. Tarjan. "A for Industrial and Ap- PA, 1983. simple version of Karzanov's blocking flow algorithm." Research Letters 2:265-268, 1984. Operations '!53(. 107 Date Due Lib-26-67 3 TDflO DOS 131 HE