12
A FAST AND SIMPLE ALGORITHM FOR THE MAXIMUM FLOW PROBLEM R. K. AHUJA Massachusetts Institute of Technology, Cambridge, Massachusetts and Indian nstitute of Technology, Kanpur, India JAMES B. ORLIN Massachusetts Institute of Technology, Cambridge, Massachusetts (Received June 1987; revisions received February, October 1988; accepted June 1988) We present a simple sequential algorithm for the maximum flow problem on a network with n nodes, m arcs, and integer arc capacities bounded by U. Under the practical assumption that U is polynomially bounded in n, our algorithm runs in time O(nm + n 2 log n). This result improves the previous best bound of O(nm log(n 2 /m)), obtained by Goldberg and Taran, by a factor of log n for networks that are both nonsparse and nondense without using any complex data structures. We also describe a parallel implementation of the algorithm that runs in O(n'log U log p) time in the PRAM model with EREW and uses only p processors where p = [m/nI. he maximum flow problem is one of the most fundamental problems in network flow theory and has been investigated extensively. This problem was first formulated by Fulkerson and Dantzig (1955) and Dantzig and Fulkerson (1956), and solved by Ford and Fulkerson (1956) using their well known augmenting path algorithm. Since then, a number of algorithms have been developed for this problem; some of them are listed in Table I. In the table, n is the number of nodes, m is the number of arcs, and U is an upper bound on the integral arc capacities. The algorithms whose time bounds involve U assume inte- gral capacities, whereas others run on arbitrary rational or real capacities. Edmonds and Karp (1972) showed that the Ford and Fulkerson algorithm runs in time O(nm 2 ) if flows are augmented along shortest paths from source to sink. Independently, Dinic (I 970) introduced the con- cept of shortest path networks, called layered net- works, and obtained an O(n 2 m) algorithm. This bound was improved to O(n 3 ) by Karzanov (1974), who introduced the concept of preflows in a layered network. A preflow is similar to a flow except that the amount flowing into a node may exceed the amount flowing out of a node. Since then; researchers have improved the complexity of Dinic's algorithm for sparse networks by devising sophisticated data struc- tures. Among these contributions, Sleator and Tarjan's (1983) dynamic tree data structure is the most attractive from a worst-case point of view. The algorithms of Goldberg (1985) and of Goldberg and Tarjan (1986) are a novel departure from these approaches in that they do not construct layered net- works. Their method maintains a preflow, as per Karzanov, and proceeds by pushing flows to nodes estimated to be closer to the sink. To estimate which nodes are closer to the sink, it maintains a distance label for each node that is a lower bound on the length of a shortest augmenting path to the sink. Distance labels are a better computational device than layered networks because the distance labels are simpler to understand, easier to manipulate, and easier to use in a parallel algorithm. Moreover, by cleverly using the dynamic tree data structure, Goldberg and Tarjan obtain the best computational complexity for sparse as well as dense networks. For problems with arc capacities polynomially bounded in n, our maximum flow algorithm is an improvement of Goldberg and Tajan's algorithm and uses concepts of scaling introduced by Edmonds and Karp for the minimum cost flow problem and later extended by Gabow (1985) for other network opti- mization problems. The bottleneck operation in the straightforward implementation of Goldberg and Tarjan's algorithm is the number of nonsaturating pushes, which is O(n3). However, they reduce the computational time to O(nm log(n 2 /m)) by a clever application of the dynamic tree data structure. We show that the number of nonsaturating pushes can be reduced to O(n 2 log U) by using excess scaling. Our Subject classification: Networks/graphs, flow algorithms: fast and simple algorithm for the maximum fl Operations Research Vol. 37, No. 5, September-October 1989 748 low problem. 0030.364X/89/3705-0748 $01.25 © 1989 Operations Research Society of Amenca Runnj No. £ 1 Ford and (1956) 2 Edmonds (1972) 3 Dinic (19 4 Karzanov 5 Cherkask, 6 Malhotra, Mahesh 7 Galil (198 8 Galil and' (1980);: (1978) 9 Shiloach a (1982) 10 Sleator ant (1983) 11 Tarjan (l19 12 Gabow (19 13 Goldberg (: 14 Goldberg a: (1986) 15 Bertsekas (i 16 Cheriyan ar Maheshw 17 Ahujaand( (this pape 18 Ahuja, Orlir Tarjan ( i algorithm modif follows. It perfk scaling iteration if we push flow, excesses to nodes never allowing ti COmputational ti n 21og U). Under the reas for some k, our n2log n). On net, nonsparse, i.e., m Our algorithm rut Goldberg and Tar Such networks by algorithm is easier efficient in practi - -- .~ SWF SW' -e -_--- -·I - - -- C II ---·------ - --- -- mommumm-m-scac~-~~----~-C··-~~---··--r-~w ~ -

A FAST AND SIMPLE ALGORITHM FOR THE MAXIMUM FLOW …

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: A FAST AND SIMPLE ALGORITHM FOR THE MAXIMUM FLOW …

A FAST AND SIMPLE ALGORITHM FORTHE MAXIMUM FLOW PROBLEM

R. K. AHUJAMassachusetts Institute of Technology, Cambridge, Massachusetts and Indian nstitute of Technology, Kanpur, India

JAMES B. ORLINMassachusetts Institute of Technology, Cambridge, Massachusetts

(Received June 1987; revisions received February, October 1988; accepted June 1988)

We present a simple sequential algorithm for the maximum flow problem on a network with n nodes, m arcs, and integerarc capacities bounded by U. Under the practical assumption that U is polynomially bounded in n, our algorithm runsin time O(nm + n2 log n). This result improves the previous best bound of O(nm log(n2 /m)), obtained by Goldberg andTaran, by a factor of log n for networks that are both nonsparse and nondense without using any complex data structures.We also describe a parallel implementation of the algorithm that runs in O(n'log U log p) time in the PRAM model withEREW and uses only p processors where p = [m/nI.

he maximum flow problem is one of the mostfundamental problems in network flow theory

and has been investigated extensively. This problemwas first formulated by Fulkerson and Dantzig (1955)and Dantzig and Fulkerson (1956), and solved byFord and Fulkerson (1956) using their well knownaugmenting path algorithm. Since then, a number ofalgorithms have been developed for this problem;some of them are listed in Table I. In the table, n isthe number of nodes, m is the number of arcs, and Uis an upper bound on the integral arc capacities. Thealgorithms whose time bounds involve U assume inte-gral capacities, whereas others run on arbitraryrational or real capacities.

Edmonds and Karp (1972) showed that the Fordand Fulkerson algorithm runs in time O(nm 2) if flowsare augmented along shortest paths from source tosink. Independently, Dinic (I 970) introduced the con-cept of shortest path networks, called layered net-works, and obtained an O(n2m) algorithm. Thisbound was improved to O(n3) by Karzanov (1974),who introduced the concept of preflows in a layerednetwork. A preflow is similar to a flow except that theamount flowing into a node may exceed the amountflowing out of a node. Since then; researchers haveimproved the complexity of Dinic's algorithm forsparse networks by devising sophisticated data struc-tures. Among these contributions, Sleator andTarjan's (1983) dynamic tree data structure is the mostattractive from a worst-case point of view.

The algorithms of Goldberg (1985) and of Goldbergand Tarjan (1986) are a novel departure from theseapproaches in that they do not construct layered net-works. Their method maintains a preflow, as perKarzanov, and proceeds by pushing flows to nodesestimated to be closer to the sink. To estimate whichnodes are closer to the sink, it maintains a distancelabel for each node that is a lower bound on the lengthof a shortest augmenting path to the sink. Distancelabels are a better computational device than layerednetworks because the distance labels are simpler tounderstand, easier to manipulate, and easier to use ina parallel algorithm. Moreover, by cleverly using thedynamic tree data structure, Goldberg and Tarjanobtain the best computational complexity for sparseas well as dense networks.

For problems with arc capacities polynomiallybounded in n, our maximum flow algorithm is animprovement of Goldberg and Tajan's algorithm anduses concepts of scaling introduced by Edmonds andKarp for the minimum cost flow problem and laterextended by Gabow (1985) for other network opti-mization problems. The bottleneck operation in thestraightforward implementation of Goldberg andTarjan's algorithm is the number of nonsaturatingpushes, which is O(n3). However, they reduce thecomputational time to O(nm log(n2/m)) by a cleverapplication of the dynamic tree data structure. Weshow that the number of nonsaturating pushes can bereduced to O(n2log U) by using excess scaling. Our

Subject classification: Networks/graphs, flow algorithms: fast and simple algorithm for the maximum fl

Operations ResearchVol. 37, No. 5, September-October 1989 748

low problem.

0030.364X/89/3705-0748 $01.25© 1989 Operations Research Society of Amenca

Runnj

No. £

1 Ford and(1956)

2 Edmonds(1972)

3 Dinic (194 Karzanov5 Cherkask,6 Malhotra,

Mahesh7 Galil (1988 Galil and'

(1980);:(1978)

9 Shiloach a(1982)

10 Sleator ant(1983)

11 Tarjan (l1912 Gabow (1913 Goldberg (:14 Goldberg a:

(1986)15 Bertsekas (i16 Cheriyan ar

Maheshw17 Ahujaand(

(this pape18 Ahuja, Orlir

Tarjan (

i

algorithm modiffollows. It perfkscaling iterationif we push flow,excesses to nodesnever allowing tiCOmputational tin 21og U).

Under the reasfor some k, ourn2log n). On net,nonsparse, i.e., mOur algorithm rutGoldberg and TarSuch networks byalgorithm is easierefficient in practi

- -- .~ SWF SW'

-e -_--- -·I - - -- C II -�--·------ - --- --

mommumm-m-scac~-~~----~-C··-~~---··--r-~w ~ -

Page 2: A FAST AND SIMPLE ALGORITHM FOR THE MAXIMUM FLOW …

e-Ss'uu6r.o|>'-V|-- a * X * .. X.... ~~?! ~?"~ ~~ ~~i~ "~~~~~~~~ ~~~-" ;:` ~.` ~ ! ~ ~ ~~ ~ ~ ..

ipur, India

, and integer,orithm runsioldberg andta structures.I model with

and of Goldbergrture from these;ruct layered net-preflow, as per

; flows to nodeso estimate whichatains a distancend on the length

te sink. Distancevice than layeredIs are simpler tod easier to use in:leverly using theberg and Tarjanplexity for sparse

ies polynomiallyalgorithm is an

n's algorithm andby Edmonds and,roblem and laterter network opti-operation in the

f Goldberg andof nonsaturatingthey reduce the

'/m)) by a cleverata structure. We:ing pushes can beccess scaling. Our

Table IRunning Times of the Maximum Flow

AlgorithmsNo. Due to Running Time

1 Ford and Fulkerson O(nm U)(1956)

2 Edmonds and Karp O(nm2 )(1972)

3 Dinic (1970) O(n2m)4 Karzanov (1974) O(n3)5 Cherkasky (1977) 0(n2 m" /2)6 Malhotra, Kumar and O(n3 )

Maheshwari (1978)7 Galil (1980) (n5/3m 2

/3

8 Galil and Naamad O(nmn log2n)(1980); Shiloach(1978)

9 Shiloach and Vishkin O(n3)(1982)

10 Sleator and Tarjan O(nm log n)(1983)

11 Tarjan (1984) O(n3)12 Gabow (1985) O(nm log U)13 Goldberg (1985) 0(n3

)

14 Goldberg and Tarjan O(nm log (n3/m))

(1986)15 Bertsekas (1986) 0(n

3)

16 Cheriyan and O(n2m

1 2')

Maheshwari (1988)17 Ahuja and Orlin O(nm + n2log U)

(this paper)18 Ahuja, Orlin and n21og U C

Tarjan (1988) (a)log og l

(b) O(nm + n2 /log C)

(c) 0(nm 10 (n log U +u M

algorithm modifies the Goldberg-Tarjan algorithm asfollows. It performs log U scaling iterations; eachscaling iteration requires O(n 2) nonsaturating pushesif we push flows from nodes with sufficiently largeexcesses to nodes with sufficiently small excesses whilenever allowing the excesses to become too large. Thecomputational time of our algorithm is O(nm +n2 log U).

Under the reasonable assumption that U = O(n ')

for some k, our algorithm runs in time O(nm +n'log n). On networks that are both nondense andnonsparse, i.e., m = (n '+ ) for some e with 0 < e < 1,our algorithm runs in time O(nm), which improvesGoldberg and Tarjan's bound of O(nm log(n2/m)) onsuch networks by a factor of log n. Moreover, ouralgorithm is easier to implement and should be moreefficient in practice, because it requires only ele-

Algorithm for the Maximum Flow Problem / 749

mentary data structures with little computationaloverheads.

This paper also describes a parallel implementationof our maximum flow algorithm. Our algorithm isdifficult to make massively parallel because the algo-rithm exploits the fact that it pushes flow from onenode at a time. Nevertheless, in the PRAM (ParallelRandom Access Machine) model with EREW (Exclu-sive Read Exclusive Write) our algorithm runs inO(n 2log U log p) time and uses only p proces-sors where p = rm/nl. This algorithm easily extendsto an O(((nm/k) + n2log U)log k) algorithm using2 < k < p processors. The existing parallel algorithmsdue to Shiloach and Vishkin (1982) and Goldberg andTarjan (1986) run in O(n2log n) time and use nprocessors. For k < n processors, their algorithms runin O((n3/k)log k) time (personal communication withAndrew Goldberg). For k < p/log U, our algorithmruns in O((nm/k)log k) time and provides a speedupof n2/m over the existing algorithms.

1. NOTATION

Let G = (N, A) be a directed network with a positiveinteger capacity u,i for every arc(i, j) E A. Let n = I N and m = A 1. The source s and sink t are twodistinguished nodes of the network. It is assumed thatfor every arc(i, j) A, an arc(j, i) is also contained inA, possibly with zero capacity. We assume withoutloss of generality that the network does not containmultiple arcs and that capacities of arcs directed intothe source or directed out from the sink are zero. Wefurther assume that none of the paths from the sourceto the sink has infinite capacity as such a path can bedetected easily in O(m) time. Observe that if thenetwork contains some infinite capacity arcs but noinfinite capacity path, then the capacity of such arcscan be replaced by X{(i.j)E.au:UO<xl Uij. We, therefore,assume that all arcs have finite capacity. Let U =max(.,.i)E. {Uj}.

A flow is a function x: A -- R satisfying

Z xi - Z x)C= 0j:(, Ui-)G-f It oj:(i.jiN)s. (t

for all i N- {s, t} (1)

E X =

0 s xi < ui for all (i, j) E A

(2)

(3)

? for some v 3 0. The maximum flow problem is todetermine a flow x for which v is maximized.

K/89/3705-0 74 8 $01'25arch Society of America

__ ._.. __-_ii- I �--�8----·-�---m�----- I

I 4't

Page 3: A FAST AND SIMPLE ALGORITHM FOR THE MAXIMUM FLOW …

750 / AHUJA AND ORLIN

A preflow x is a function x: A -* R that satisfies (2),(3), and the following relaxation of (I)

xi - X x, > Oj:j.i)e. 1 j:( ij)E I }

for all i E N- {s, t . (4)

The algorithms described in this paper maintain apreflow at each intermediate stage.

For a given preflow x, we define for each nodei E N- {s, t , the excess

e,= x,- x,.:;~i~i'i (j:.)E. . , lJ:(,;j)C.I1

A node with positive excess is referred to as anactive node. We define the excesses of the source andsink nodes to be zero; consequently, these nodes arenever active. The residual capacity of any arc (i, j) EA, with respect to a given preflow x, is given by r =., __ ,.- A_ v T1. ...-;,.1.,1 .. .;+ , ...( ..,/; ;\ .....u/- Ai T Aji. lF 1e lCiUUili 44l1Ly 1 V 1 ailit, ) peC-

sents the maximum additional flow that can be sentfrom node i to node j using the arcs (i, j) and (j, i).The network that consists only of arcs with positiveresidual capacities is referred to as the residual net-work. Figure illustrates these definitions.

We define the arc adjacency list A(i) of a nodei F: NT as the et r nt nf nrrthe noe i i A(i) := {(i, k) G A:k E NJ. Note that our adjacencylist is a set of arcs rather than the more conventionaldefinition of the list as a set of nodes.

A distance function d: N -- Z for a preflow x is afunction from the set of nodes to the nonnegativeintegers. We say that a distance function d is valid ifit also satisfies the following two conditions:

Ci. d(t)= 0;C2. d(i) < d(j) + 1 for every arc (i, j) E A with

.... , rjr>0.

Our algorithm maintains a valid distance functionat each iteration. We also refer to d(i) as the distancelabel of node It is easv to demonstrate hv inductionthat d(i) is a lower bound on the length of the shortestpath from i to t in the residual network. Let i = i -i2 - ... -i - k+l = t be any path of length k in theresidual network from node i to the sink. Then fromcondition C2 we have, d(i) = d(il) < d(i2) + 1,d(i2) < d(i3) + 1 ... , d(ik) < d(ik+) + = 1. Thisyields d(i) < k for any path of length k in the residualnetwork and, hence, must also hold for the shortestpath. If for each i, the distance label d(i) equals theminimum length of any path from i to t in the residualnetwork, then we call the distance label exact. Forexample, in Figure Ic, d = (0, 0, 0, 0) is a valid

4 424A 3

2 1

a. Network with arc capacities.Node 1 is the source and node 4 issink. (Arcs with zero capacities arenot shown.)

e3= 1

b. Network with a preflow x

c. The residual network withresidual arc capacities

Figure 1. Illustrations of a preflow and the residualnetwork.

distance label, though d = (3, 1, 2, 0) represents theexact distance label.

An arc (i, j) in the residual network is called admis-sible if it satisfies d(i) = d(j) + 1. An arc that is notadmissible is called an inadmissible arc. The algo-rithms discussed in this paper push flow only onadmissible arcs. Lastly, all algorithms in this paper areassumed to be of base 2 unless stated otherwise.

2. PREFLOW-PUSH ALGORITHMS

The preflow-push algorithms for the maximum flowproblem maintain a preflow at every step and proceedby pushing the node excesses closer to the sink. Thefirst preflow-push algorithm is due to Karzanov.Tarjan (1984) has suggested a simplified version ofthis algorithm. The recent algorithms of Goldberg(1985) and Goldberg and Tarjan (1986) are based onideas similar to those presented in Tarjan, but they

a : :.....

ata,

P.

ct,t

t

i

I

i

I

I

t

I

i.

I

i

iII

t1i

I

a

i

___ ---------- _ ~ C. ~r~-.~ LIIIILII - iC--- ~ CCI- I --~-PCIIILIII~-~-L-*glY~·l i~--~- ~ L I~C------C----~--~--·~IOIII11~·C_3··~CIP - ___ in q

i

ii

i

I

i

i

E

i

i

I

-

""^r

··*,",' ��·1.�����- ��·,··_r�:�·�··,� ·-��·.��

Page 4: A FAST AND SIMPLE ALGORITHM FOR THE MAXIMUM FLOW …

use distance labels to direct flows closer to the sinkinstead of constructing layered networks. We refer totheir algorithm as the (distance-directed) preflow-pushalgorithm. In this section, we review the basic featuresof their algorithm, which for the sake of brevity, wesimply refer to as the preflow-push algorithm. Herewe describe the -phase version of the preflow-pushalgorithm presented by Goldberg (1987). The resultsin this section are due to Goldberg and Taran (1986).

All operations of the preflow-push algorithm areperformed using only local information. At each iter-ation of the algorithm (except at the initialization andat the termination) the network contains at least oneactive node, i.e., a nonsource and nonsink node withpositive excess. The goal of each iterative step is tochoose some active node and to send its excess closerto the sink, with closer being judged with respect tothe current distance labels. If excess at this nodecannot be sent to nodes with smaller distance labels,then the distance label of the node is increased. Thealgorithm terminates when the network contains noactive nodes. The preflow-push algorithm uses thefollowing subroutines:

Algorithm for the Maximum Flow Problem / 751

Figure 2 illustrates the steps PUSH(i) andRELABEL(i) as applied to the network in Figure la.The number beside each arc represents its residualcapacity. Figure 2a specifies the residual network afterthe PREPROCESS step. Suppose the algorithm selectsnode 2 for examination. Since arc (2, 4) has a residualcapacity r24 = 1 and d(2) = d(4) + 1, the algorithmperforms a saturating push of value 6 = min{2, 11units. The push reduces the excess of node 2 to 1.Arc (2, 4) is deleted from the residual network and

d(3) = 1e3 =4

4

d(1) = 4

2

3

d(4) = 0

1

d(2) = 1e2 =2

nd the residual

) represents the

is called admis-i arc that is notarc. The algo-

i flow only onin this paper areotherwise.

maximum flowtep and proceed.o the sink. The

to Karzanov.ified version ofns of Goldberg16) are based onarjan, but they

PREPROCESS. On each arc (s, j) E A(s), send u,units of flow. Let d(s) = n and d(t) = O. Let d(i) = 1for each i $ s or t. (Alternatively, any valid labelingcan be used, e.g., the distance label for each nodei s, t can be determined by a backward breadth firstsearch on the residual network starting at node t.)

PUSH(i). Select an admissible arc (i, j) in A(i). Send6 = minte;, rij} units of flow from node i to j.

We say that a push of flow on arc (i, j) is saturatingif 6 = r,, and nonsaturating otherwise.

RELABEL(i). Replace d(i) by mintd(j) + 1 : (i, j) EA(i) and r > 0}.

This is called a relabel step. The result of the relabelstep is to create at least one admissible arc on whichfurther pushes can be performed.

The generic version of the preflow-push algorithmis given below.

algorithm PREFLOW-PUSH;begin

PREPROCESS;while there is an active node dobegin

select an active node i;if there is an admissible arc in A(i) then PUSH(i)else RELABEL(i);

end;end.

(a) The residual network after the pre-processing step.

d(3) = 1e3 =4

4

d(1) =4

2

3

d(4) =

1

d(2) =)e2 =

(b) After the execution of step PUSH(2).

d(3) = 1e3 =4

4

d(l) =4

2

3

d(4) =0

I

d(2) = 2e =1

(c) After the execution of step RELABEL(2).

Figure 2. Illustrations of push and relabel steps.

ri5�·'��s r··51-�:4�;·4·is4CWd·�;'t·r;�5j�t�EJF�g�j�i���t-�R '-r ��i��j\lli-* lrr4li iLm�Lm�l���l�:Y:�·�:,�fi� ,II-j� ,,:,i ··rt ;R�- :";114i il:ig� r �-.; ·-· I··� .: :r n-· :'wr1.1 if� 1: �

�trr�ssaa*·------·-rrr�--·ll-. __ �PglC-"--C I-·IIR -·-- --·

Page 5: A FAST AND SIMPLE ALGORITHM FOR THE MAXIMUM FLOW …

752 / AHUJA AND ORLIN

arc (4, 2) is added to the residual network. Sincenode 2 is still an active node, it can be selected againfor further pushes. Arcs (2, 3) and (2, 1) have posi-tive residual capacities, but they do not satisfy thedistance condition. Hence, the algorithm performsRELABEL(2), and gives node 2 a new distanced'(2) = min{d(3) + 1, d(l) + 1} = min{2, 5} = 2.

The preprocess step accomplishes several importanttasks. First, it causes the nodes adjacent to s to havepositive excess, so that subsequently we can selectnodes for push or relabel steps. Second, by saturatingarcs incident to s, the feasibility of setting d(s) = n isimmediate. Third, since the distance label d(s) = nis a lower bound on the length of the minimum pathfrom s to t, there is no path from s to t after thePREPROCESS step. Furthermore, since distancelabels are nondecreasing (see Lemma 1), we also areguaranteed that in subsequent iterations the residualnetwork will never contain a directed path from s tot, and so there can never be any need to push flowfrom s again.

In our improvement of the preflow-push algorithm,we need a few of the results given in Goldberg andTarjan (1986). We include some of their proofs inorder to make this presentation more self-contained.The interested reader is encouraged to read the origi-nal paper by Goldberg and Tarjan which discussesother versions of preflow-push algorithms.

Lemma 1. The generic preflow-push algorithm main-tains valid distance labels at each step. Moreover, ateach relabel step the distance label of some nodestrictly increases.

Proof. First note that the preprocess step constructsvalid distance labels. Assume inductively that the dis-tance function is valid prior to an operation, i.e., itsatisfies the validity conditions CI and C2. A pushoperation on the arc (i, j) may create an additionalarc (j, i) with rji > 0, and an additional condition d(j)< d(i) + I needs to be satisfied. This validity conditionremains satisfied since d(i) = d(j) + 1 by the propertyof the push operation. A push operation on arc (i, j)might delete this arc from the residual network, butthis does not affect the validity of the distance func-tion. During a relabel step, the new distance label ofnode i is d'(i) = min{d(j) + 1: (i, j) E A(i) andrij > 0O, which again is consistent with the validityconditions. The relabel step is performed when thereis no arc (i, j) E A(i) with d(i) = d(j) + 1 andr, > 0. Hence, d(i) < minfd(j) + 1: (i, j) E A(i) andri > 0} = d'(i), thereby proving the second part of thelemma.

Lemma 2. At any stage of the preflow-push algorithm,for each node i with positive excess, there is a directedpath from node i to node s in the residual network.

Proof. By the flow decomposition theory of Ford andFulkerson, any preflow x can be decomposed withrespect to the original network G into the sum ofnonnegative flows along: i) paths from s to t, ii) pathsfrom s to active nodes, and iii) flows around directedcycles. Let i be an active node relative to the preflowx in G. Then, there must be a path P from s to i inthe flow decomposition of x because paths from s tot and flows around cycles do not contribute to theexcess at node i. Then the reversal of P (P with theorientation of each arc reversed) is in the residualnetwork, and hence, there is a path from i to s in theresidual network.

Corollary 1. For each node i E N, d(i) < 2n.

Proof. The last time node i was relabeled, it had apositive excess, and hence, the residual network con-tained a path of length at most n - 1 from i to s. Thefact that d(s) = n and condition C2 imply that d(i) <d(s) + n - < 2n.

Lemma 2 also implies that a relabel step neverminimizes over an empty set.

Corollary 2. The number of relabel steps is less than2n 2.

Proof. Each relabel step increases the distance labelof a node by at least one, and by Corollary I no nodecan be relabeled more than 2n times.

Corollary 3. The number of saturating pushes is nomore than nm.

Proof. Suppose that arc (i, j) becomes saturated atsome iteration (at which time d(i) = d(j) + 1). Thenno more flow can be sent on (i, j) until flow is sentback from j to i, at which time d'(j) = d'(i) + 1 >d(i) + 1 = d(j) + 2; this flow change cannot occuruntil d(j) increases by at least 2. Thus by Corollary I,arc (i, j) can become saturated at most n times, andthe total number of arc saturations is no more thannm. (Recall that we assume that (i, j) and (j, i) areboth in A, so the number of arcs in the residualnetwork is no more than m.)

Lemma 3. The number of nonsaturating pushes is atmost 2n 2m.

Ci

iir

I

Ii

izi

iz

iiIr

iI

jrit

f

i

i

fi1

iI

-.···. L����::' ··-

�;<·.2:

J

_ ·- --·--n M- ---- l·~--- --- . el ~ .~ _i____---~

··�

':I

i.·

i

ii

i

·· ,·..·�·, .·, ·.··,c

··'x'·� IrCylCc I. ,·�r

.j

�·1.i.

ii.ii1

1

ii

5j

j

".·"·.':·".�..:

r��··�·�:·�-r�r �r

Page 6: A FAST AND SIMPLE ALGORITHM FOR THE MAXIMUM FLOW …

ush algorithm,,re is a directedial network.

ry of Ford and:omposed withto the sum ofs to t, ii) pathsround directedto the preflow

'from s to i in)aths from s tontribute to theP (P with the

in the residual)m i to s in the

)< 2n.

beled, it had atl network con-rom i to s. Theiply that d(i) <

ibel step never

,eps is less than

e distance labelIlary 1 no node

qg pushes is no

ies saturated atd(j) + 1). Thenntil flow is sent)= d'(i)+ 1 ge cannot occur

by Corollary 1,)st n times, ands no more thani) and (j, i) arein the residual

ting pushes is at

Proof. See Goldberg and Tarjan (1986).

Lemma 4. The algorithm terminates with a maximumflow.

Proof. When the algorithm terminates, each node inN - Is, t} has zero excess; so the final preflow is afeasible flow. Furthermore, since the distance labelssatisfy conditions C1 and C2 and d(s) = n, it followsthat upon termination, the residual network containsno directed path from s to t. This condition is theclassical termination criterion for the maximum flowalgorithm of Ford and Fulkerson.

The bottleneck operation in many preflow-basedalgorithms, such as the algorithms due to Karzanov;Tarjan; and Goldberg and Tarjan (1986), is the num-ber of nonsaturating pushes. A partial explanation ofwhy the number of nonsaturating pushes dominatesthe number of saturating pushes is as follows: Thesaturating pushes cause structural changes-theydelete saturated arcs from the residual network. Thisobservation leads to a bound of O(nm) on the numberof saturating pushes-no matter in which order theyare performed. The nonsaturating pushes do notchange the structure of the residual network and seemmore difficult to bound. Goldberg (1985) showed thatthe number of nonsaturating pushes is O(n3 ) whennodes are examined in a first-in first-out order.Goldberg and Tarjan ( 1986) reduced the running timeof this algorithm by using dynamic trees to reduce theaverage time per nonsaturating push. Cheriyan andMaheshwari (1988) showed that the number of non-saturating pushes can be decreased to O(n2m/2) ifflow is always pushed from a node with a highestdistance label, and they showed that this bound istight. They also showed that the bounds O(n 2m) andO(n3 ) are, respectively, tight for the generic preflow-push and first-in first-out preflow-push algorithms. Inthe next section, we show that by using scaling, wecan dramatically reduce the number of nonsaturatingpushes to O(n2log U). We recently discovered newscaling algorithms that further reduce the number ofnonsaturating pushes to O(n 2log U/log log U) or toO(n' log Ui). These results are presented in Ahuja,Orlin and Tarjan (1988).

3. THE EXCESS SCALING ALGORITHM

Our maximum flow algorithm improves the genericpreflow-push algorithm of Section 2 by using excessscaling to reduce the number of nonsaturating pushes

Algorithm for the Maximum Flow Problem / 753

from O(n2m) to O(n 2log U). The basic idea is to pushflow from active nodes with sufficiently large excessesto nodes with sufficiently small excesses while neverletting the excesses become too large. We refer to ouralgorithm as the excess scaling algorithm.

The algorithm performs K= Flog U1 + 1 scalingiterations. For a scaling iteration, the excess-dominator is defined to be the least integer A that is apower of 2 and satisfies e, s A for all i E N. Further-more, a new scaling iteration is considered to havebegun whenever decreases by a factor of 2. In ascaling iteration, we guarantee that each nonsaturatingpush sends at least A/2 units of flow and that theexcess-dominator does not increase. To ensure thateach nonsaturating push has a value of at least A/2,we consider only nodes with an excess more thanA/2; and among these nodes with large excess, weselect a node with a minimum distance label. Thischoice ensures that the flow will be sent to a nodewith a small excess. We show that after at most8n2 nonsaturating pushes, the excess-dominator de-creases by a factor of at least 2, and a new scalingiteration begins. After at most K scaling iterations, allnode excesses drop to zero and we obtain a maximumflow.

In order to select an active node with excess morethan A/2 and with a minimum distance label amongsuch nodes, we maintain the lists LIST(r) = {i E N:e, > A/2 and d(i) = r} for each r = I, ... , 2n - 1.These lists can be maintained in the form of eitherlinked stacks or queues (see, for example, Aho, Hop-croft and Ullman 1974), which enables insertion anddeletion of elements in 0(1) time. The variable levelrepresents a lower bound on the smallest index r forwhich LIST(r) is nonempty.

As per Goldberg and Tarjan, we use the followingdata structure to efficiently select the admissible arcfor pushing flow out of a node. We maintain witheach node i the list, A(i), of arcs directed out of it.Arcs in each list can be arranged arbitrarily, but oncethe order is decided, it remains unchanged throughoutthe algorithm. A special arc named null is appendedto the end of each list. Each node i has a current arc(i, j), which is the current candidate for pushing flowout of i. Initially, the current arc of node i is the firstarc in its arc list. This list is examined sequentially,and whenever the current arc is found to be inadmis-sible for pushing flow, the next arc in the arc list ismade the current arc. When the arc list has beenexamined completely, the null arc is reached. At thistime, the node is relabeled and the current arc is againset to the first arc in the arc list.

.. .· ...li

; , iDi- ; <- ! ·t

- .I II I N I ---- - II., -- ---- JI- b-- ·-- I W ·II L I~·

i

* .BiA; -

Page 7: A FAST AND SIMPLE ALGORITHM FOR THE MAXIMUM FLOW …

754 / AHUJA AND ORLIN

The algorithm can be formally described asfollows.

Algorithm MAX-FLOW;begin

PREPROCESS;K:= 1 + rlog U1;for k = 1 to Kdobegin

A = 2K- k

for each i E N do if e, > A/2 then add i toLIST(d(i));

level := 1;while level < 2n do

if LIST(level) = 0 then level := level + 1elsebegin

select a node i from LIST(level);PUSH/RELABEL(i);

end;end;

end;

Procedure PUSH/RELABEL(i);begin

found := false;let (i, j) be the current arc of node i;while found = false and (i, j) # null do

if d(i) = d(j) + 1 and ri > 0 then foundtrue

else replace the current arc of node i by the nextarc (i, j);

if found = true then {found an admissible arc}begin

push minfe, r, A - ej} units of flow on arc(i, j);update the residual capacity ri and the excesses e1

and ej;if (the updated excess) e < A/2, then delete node

i from LIST(d(i));if j • s or t and (the updated excess) ej > A/2,

then add node j to LIST(d(j)) and set levellevel - 1;

endelse {finished arc list of node i}begin

delete node i from LIST(d(i));update d(i) := min{d(j) + 1; (i, j) E A(i) and

ri > 0;add node i to LIST(d(i)) and set the current arc

of node i to the first arc of A(i);end;

end.

4. COMPLEXITY OF THE ALGORITHM

In this section, we show that the distance directedpreflow-push algorithm with excess scaling correctlycomputes a maximum flow in O(nm + nlog U) time.

Lemma 5. The excess scaling algorithm satisfies thefollowing two conditions:

C3. Each nonsaturating push from a node i to a nodej sends at least A/2 units offlow.

C4. No excess increases above A (i.e., the excess-dominator does not increase subsequent to apush).

Proof. For every push on arc (i, j) we have e, > A/2and e < A/2 because node i is a node with the smallestdistance label among nodes whose excess is more thanA/2, and d(j) = d(i) - 1 < d(i) by the property ofthe push operation. Hence, by sending min{e, r,A - ej} > min{A/2, r,,} units of flow, we ensure thatin a nonsaturating push the algorithm sends at leastA/2 units of flow. Furthermore, the push operationincreases the excess at node j only. Let e be the excessat node j after the push. Then e,' = e + minfe,, r,,A - e} e + A - e, < A. All node excesses thusremain less than or equal to .

While there are other ways of ensuring that thealgorithm always satisfies the properties stated in C3and C4, pushing flow from a node with excess greaterthan A/2 and with minimum distance among suchnodes is a simple and efficient way of enforcing theseconditions.

With properties C3 and C4, the push operation maybe viewed as a kind of restrained greedy approach.Property C3 ensures that the push from i to j issufficiently large to be effective. Property C4 ensuresthat the maximum excess never exceeds A during aniteration. In particular, rather than greedily getting ridof all its excess, node i shows some restraint to preventej from exceeding A. Keeping the maximum excesslower may be useful in practice as well as in theory.Its major impact is to encourage flow excesses to bedistributed fairly equally in the network. This distri-bution of flows should make it easier for nodes tosend flow towards the sink. This also may be impor-tant because of the following consideration: supposeseveral nodes send flow to a single node j creating alarge excess. It is likely that node j is not able to sendthe accumulated flow closer to the sink, in which case,its distance label increases and much of its excess hasto be returned. This phenomenon is prevented bymaintaining condition C4.

Lemma 6. 1C4, then thscaling iterai

Proof. Consd(i)/A. The:A-scaling itebounded byalgorithm ex,cases must a;

Case 1. Thewhich flow cZcurrent arc ofthat if an arcthen it remtbecause d(j) iadmissible arcoperation inciF by at mostthroughout th,bounded by 2ings of nodes is(Actually, theat most 2n 2 ov

Case 2. The awhich flow carsaturating or adecreases. A ncleast A/2 units d(j) = d(i)- 1As the initial vaincreases in F occur more tha

Theorem 1. TIlog U) nonsatur

Proof. The initi2r°gL'" < 2U. B\dominator decrnonsaturating pbegins. After IA < 1; and by thi e N - s, t. 'Iflow, which by L

Theorem 2. Therithm is O(nm +

Proof. The compthe number of emain program.

7*~~~~~~~~~~~~~~~~~~~~~~~~"

I

1

,.k'V Y-.k mm ;w~~,~8;~-$·,;·?-r·r;·l~~~~~~~~r-- 7 -i

Page 8: A FAST AND SIMPLE ALGORITHM FOR THE MAXIMUM FLOW …

istance directed;caling correctly1- n2log U) time.

Fhm satisfies the

node i to a node

i.e., the excess-gubsequent to a

ve have ei > A/2with the smallestcess is more than/ the property ofiding minle, r,,v, we ensure thatim sends at least

push operationIt e, be the excess= ej + mintei, r 1,,)de excesses thus

insuring that therties stated in C3ith excess greaterince among suchof enforcing these

ish operation maygreedy approach.

;h from i to j isoperty C4 ensuresceeds A during angreedily getting ridestraint to preventmaximum excesswell as in theory.

low excesses to betwork. This distri-asier for nodes toiso may be impor-.ideration: suppose

node j creating ais not able to send;ink, in which case.ch of its excess hasn is prevented b}

Lemma 6. If each push satisfies conditions C3 andC4, then the number of nonsaturating pushes perscaling iteration is at most 8n2.

Proof. Consider the potential function F = Ej, e,d(i)/. The initial value of F at the beginning of theA-scaling iteration is bounded by 2n2 because e isbounded by A and d(i) is bounded by 2n. When thealgorithm examines node i, one of the following twocases must apply.

Case 1. The algorithm is unable to find an arc alongwhich flow can be pushed. This case occurs when thecurrent arc of node i reaches the end of A(i). Observethat if an arc (i, j) is found to be inadmissible earlier,then it remains inadmissible until d(i) increasesbecause d(j) is nondecreasing. Hence, there exists noadmissible arc emanating from node i and the relabeloperation increases d(i) by e > 1 units. This increasesF by at most e units. Since the total increase in d(i)throughout the running of the algorithm for each i isbounded by 2n, the total increase in F due to relabel-ings of nodes is bounded by 2n2 in the scaling iteration.(Actually, the increase in F due to node relabelings isat most 2n 2 over all scaling iterations.)

Case 2. The algorithm is able to identify an arc onwhich flow can be pushed and so it performs either asaturating or a nonsaturating push. In either case, Fdecreases. A nonsaturating push on arc (i, j) sends atleast A/2 units of flow from node i to node j and sinced(j) = d(i) - 1, this decreases Fby at least 1/2 units.As the initial value of F for a scaling iteration plus theincreases in F sum to at most 4n 2, this case cannotoccur more than 8nt times.

Theorem 1. The scaling algorithm performs O(n 2

log U) nonsaturating pushes.

Proof. The initial value of the excess-dominator is2'° gt' l < 2U. By Lemma 6, the value of the excess-dominator decreases by a factor of 2 within 8n 2

nonsaturating pushes and a new scaling iterationbegins. After 1 + Flog U1 such scaling iterations,A < 1; and by the integrality of the flow e = 0 for allI E N - s, t}. The algorithm thus obtains a feasiblefow, which by Lemma 4 must be a maximum flow.

Theorem 2. The complexity of the excess scaling algo-rithm is O(nm + n2log U).

Proof. The complexity of the algorithm depends uponthe number of executions of the while loop in the

Algorithm for the Maximum Flow Problem / 755

PUSH/RELABEL(i) step is performed or the value ofthe variable level increases. Each execution of theprocedure PUSH/RELABEL(i) results in one of thefollowing outcomes.

Case 1. A push is performed. Since the number ofsaturating pushes is O(nm) and the number ofnonsaturating pushes is O(n 2log U), this case occursO(nm + n2log U) times.

Case 2. The distance label of node i goes up. ByCorollary , this case can occur O(n) times for eachnode i and O(n2) in total.

Thus the algorithm calls the procedure PUSH/RELABEL O(nm + n21og U) times. The effort neededto find an arc to perform the push operation is 0(1)plus the number of times the current arc of node i isreplaced by the next arc in A(i). After I A(i) I suchreplacements for node i, Case 2 occurs and thedistance label of node i goes up. Thus, the totaleffort needed is ZE 2n I A(i) I = O(nm) plus the num-ber of PUSH/RELABEL operations. This is clearlyO(nm + n'log U).

Next consider the time needed for relabeling oper-ations. Computing the new distance label of node irequires examining arcs in A(i). This yields a total ofEie,, 2n I A(i) I = O(nm) time for all relabeling oper-ations. The lists LIST(r) are stored as linked stacksand queues, hence, addition and deletion of any ele-ment takes 0(1) time. Consequently, updating theselists is not a bottleneck operation.

Finally, we need to bound the number of increasesof the variable level. In each scaling iteration, level isbounded above by 2n - and bounded below by 1.Hence, its number of increases per scaling iteration isbounded by the number of decreases plus 2n.Furthermore, level can decrease only when a pushis performed and, in such a case, it decreasesby . Hence, its increases over all scaling itera-tions are bounded by the number of pushes plus2n(l + Flog U1), which is again O(nm + n21og U).

5. REFINEMENTS

As a practical matter, several modifications of thealgorithm might improve its actual execution timewithout affecting its worst-case complexity. We sug-gest three modifications:

I 1. Modify the scale factor.2. Allow some nonsaturating pushes of a small

amount.3. Try to locate nodes disconnected from the sink.main program. In each such execution, either a

+r'-iR~~~~~~~~~~~~~~~i4Li ~~~~~~~~~~~~~L~~~~~r~~~~~d-~lae:r~~~,ir~~r*·i~~~·;srz~~~··~~-~~.-2:-~~~·,rrr l-A:i U?);L ,;,V 00

f~\·l----.---""---· - -.- I1-~------~I-- 1·--- ....- -- -- - - .-- II-II I-NF--

Page 9: A FAST AND SIMPLE ALGORITHM FOR THE MAXIMUM FLOW …

756 / AHUJA AND ORLIN

The first suggestion is to consider the scale factor.The algorithm in the present form uses a scale factorof 2, i.e., it reduces the excess-dominator by a factorof 2 in each scaling iteration. In practice, however,some other fixed integer scaling factor a 2 mightyield better results. The excess-dominator then will bethe least power of A that is no less than the excess atany node, and property C3 becomes the following.

C3'. Each nonsaturating push from a node i to a nodej sends at least A/f units of flow.

The scaling algorithm presented earlier easily canbe altered to incorporate the 3 scale factor by lettingLIST(r) = i E N:e > A/f and d(i) = r}. Thealgorithm can be shown to run in O(nm + in 2log U)time. From the worst-case point of view any fixedvalue of : is optimum; the best choice for the valueof /3 in practice should be determined empirically.

The second suggestion focuses on the nonsaturatingpushes. Our algorithm as stated selects a node withei > A/2 and performs a saturating or a nonsaturatingpush. We could, however, keep pushing the flow outof this node until either we perform a nonsaturatingpush of a value at least /2 or reduce its excess tozero. This variation might produce many saturatingpushes from the node and even allow pushes after itsexcess decreases below /2. Also, the algorithm asstated earlier sends at least /2 units of flow duringevery nonsaturating push. The same complexity ofthe algorithm is obtained if for some fixed r 1, oneout of every r 1 nonsaturating pushes sends at leastA/2 units of flow.

The third suggestion recognizes that in practice onepotential bottleneck is the number of relabels. Inparticular, the algorithm recognizes that the residualnetwork contains no path from node i to node t onlywhen d(i) exceeds n - 2. Goldberg (1987) suggestedthat it may be desirable to occasionally perform abreadth first search to make the distance labels exact.He discovered that a judicious use of breadth firstsearch dramatically speeds up the algorithm.

An alternative approach is to keep track of thenumber n, of nodes whose distance is k. If n decreasesto 0 after any relabel for some k, then each node witha distance greater than k is disconnected from the sinkin the residual network. (Once node j is disconnectedfrom the sink, it stays disconnected since the shortestpath from j to t is nondecreasing in length.) We avoidselecting such nodes until all nodes with positiveexcess become disconnected from the sink. At thistime, the excesses of the nodes are sent back to thesource. This approach essentially yields the two phaseapproach to solve the maximum flow problem as

outlined in Goldberg and Tarjan (1986). The firstphase constructs a maximum preflow that is convertedto a maximum flow in the second phase.

6. PARALLEL IMPLEMENTATION

In this section, we describe a parallel implementationof the excess scaling algorithm. We analyze this imple-mentation in the PRAM (Parallel Random AccessMachine) Model with EREW (Exclusive Read Exclu-sive Write). Our algorithm runs in O(n log U log p)time and uses p processors, where p = mn/n. Moregenerally, our algorithm runs in O(((nm/k) + nlogU)log k) time for any k s p. We describe the algorithmfor k = p processors, but the extension to k < p isimmediate.

Our algorithm performs the following parallel prefixoperations.

Operation . Given I/ p numbers d(jj), d(j), ... ,d(j), determine the minimum of these numbers.

Operation 2. Given I < p numbers f(j,), f(j 2),f(j), compute the partial sums f(j,), f(j,) + f(j2),f(j,) + f(j 2) + f(j3), ... ,f(j) +f(j 2) + ... + f(j/).

Operation 3. Given l p numbers F(j,), F(j), ... ,F(j,), such that F(j,) s F(j2) ... F(j/) A/2,determine the minimum index wt such that F(j,,) A/2.

Operation 4. Given l < p numbers e(j,), e(jJ), .. e(jf), form the doubly linked list of numbers whosevalue is more than A/2.

Using a parallel prefix, each of these operations canbe performed in O(log p) time using p/(log p) proces-sors (see Kindervater and Lenstra 1988 for Operations1 and 2, and Dekel and Sahni 1983 for Operation 3.)Operation 4 can also be performed in O(log p) timeusing recursive doubling (personal communicationwith J. K. Lenstra).

A straightforward parallel implementation of theexcess scaling algorithm requires n processors. Ourreduction of the number of processors required by thealgorithm is based on the following method. Whileperforming a push at node i or relabeling this node,the algorithm does not consider all arcs in A(i) simul-taneously, but it partitions arcs in A(i) into groups,each containing at most p arcs, and considers onlyone group at a time. For example, while relabel-ing node i, the algorithm sequentially examinesr A(i) I/pl groupings and using Operation 1 computesthe minimum of a group in O(log p) time. Since any

C- i' ''' , - o,-~"'A ''C -a.~~~~~~~~~~l'N4

·. . d·f I·S; T4·'3~U~'-i$ iiiiia ~ f= "' ra~c~r i'%:~~p~rrPTi .r:u-~: :i'

node can be relabnumber of groups e

Ai (2n)

E A(i) +

Thus, partitioningincrease the compu

Our parallel algo:BEL(i) step on a gralgorithm maintaingroup, which playsdoes for the sequenof the node i is nuexamined), then tYassigns a parallel pwhich easily can barcs in this group t/l • p. Each processeto and defines a admissible, and f(,rithm performs Ofsums of the f(t) vafollowing two cases

Case 1. f(i) + f(Jrithm saturates alupdates the residuathe nodes, and repl;the next group.

Case 2. f(jl) + f(Jrithm performs Ofpartial sums at thearcs (i, j), (i, j2),.

saturating push o:A - e(j.)} on arcresidual capacities 4

Let e(j) denoteboth cases. The a:tion 4 on numbersdoubly linked list Lthen the variable le

We count the nuperformed by thealgorithm results i]a) the algorithm saalgorithm perform,algorithm relabelsmost n times, the ibounded by E n r

"V- � - .,Ilt,� , --,, ---" e�� P,��,,- , "aMM "� -- �- ---P, N

4t

ii

i

d

Page 10: A FAST AND SIMPLE ALGORITHM FOR THE MAXIMUM FLOW …

1986). The firstthat is convertedase.

implementationalyze this imple-Zandom Accessive Read Exclu-}(n2log U log p)= m/ni. More(nm/k) + n2 logie the algorithmion to k p is

Ig parallel prefix

(j1), d(j2 ), .

e numbers.

c(jI), f(j2), ... ,

), f(ji) + f(j),... +f(j,).

'(j, ), F(j2),. ,< F(j) > 6/2,:h that F(j,,) >

'(j~), e(j2), .numbers whose

operations can'/(log p) proces-j for Operations)r Operation 3.)1 O0(log p) time:ommunication

sntation of the)rocessors. Ourrequired by themethod. While-ling this node,:s in A(i) simul-(i) into groups,considers onlywhile relabel-

.ially examines-ion I computestime. Since any

node can be relabeled at most 2n times, the totalnumber of groups examined for all nodes is

( 2n)i (lAi)j + ( (2n) - + n (2n) < 4n

Thus, partitioning arcs in A(i) into groups does notincrease the computational time in the worst case.

Our parallel algorithm performs the PUSH/RELA-BEL(i) step on a group of arcs in A(i) in parallel. Thealgorithm maintains for each node i an index currentgroup, which plays the same role as the current arcdoes for the sequential algorithm. If the current groupof the node i is null (i.e., all of its groups have beenexamined), then the node is relabeled. Otherwise itassigns a parallel processor to each arc in the groupwhich easily can be done in O(log p) time. Let thearcs in this group be (i, jl), (i, j2), . . . , (i, j) for someI < p. Each processor checks the arc (i, j) it is assignedto and defines a number f(j) = r,j if arc (i, j) isadmissible, and f(j) = 0 otherwise. Then the algo-rithm performs Operation 2 to compute the partialsums of the f(. ) values. This operation results in thefollowing two cases.

Case 1. f(j) + f(j2) + ... + f(j) < A/2. The algo-rithm saturates all admissible arcs in the group,updates the residual capacities of arcs and excesses atthe nodes, and replaces the current group of node i bythe next group.

Case 2. f(ji) + f(j2) + ... + f(jf) > A/2. The algo-rithm performs Operation 3 with F(.) equal to thepartial sums at the nodes. The algorithm saturates allarcs (i, (i, j, ), . . .; (i, j,.- ) and performs a non-saturating push of value min{e(i) - F(j,,t-), ri,,A - e(j,,)} on arc (i, j,.). The algorithm updates theresidual capacities of arcs and excesses at the nodes.

Let e(j) denote the updated excesses of nodes inboth cases. The algorithm finally performs Opera-tion 4 on numbers e(j), e(j2), . . ., e(j/) to form thedoubly linked list LIST(d(jl)). If this list is nonempty,then the variable level is also updated.

We count the number of parallel prefix operationsperformed by the algorithm. Each iteration of thealgorithm results in one of the following outcomes:a) the algorithm saturates all arcs in a group; b) thealgorithm performs a nonsaturating push; and c) thealgorithm relabels a node. Since an arc is saturated atmost n times, the number of occurrences of case a isbounded by AZi, ri A(i) I/pln -< 2n2. Each occurrence

Algorithm for the Maximum Flow Problem / 757

of case b pushes at least A/2 units of flow; hence, thiscase occurs at most O(n21og U) times. The algorithmperforms 0(1) parallel prefix operations for eachoccurrence of case a and case b. Furthermore, it hasbeen shown that the algorithm performs at most 4n2

parallel prefix operations during all relabel steps. Con-sequently, the algorithm performs O(n21og U) parallelprefix operations and runs in O(n21og U log p) time.

The only modification to the algorithm for k < pparallel processors is that the arcs in each adjacencylist A(i) are partitioned into groups of at most k arcs.In this case, the number of parallel prefix operationsfor group saturations and node relabeling is O(nm/k)and the number of nonsaturating pushes remainsunchanged. We have, thus, established the followingresult.

Theorem 3. In the PRAM model with EREW, theparallel excess scaling algorithm runs in O(((nm/k) +n2log U)log k) time using k < p processors.

7. RELATED RESEARCH

Our improvement of the distance directed preflow-push algorithm has several advantages over other algo-rithms for the maximum flow problem. Our algorithmis superior to all previous algorithms for the maximumflow problem under the reasonable assumption thatU is polynomially bounded in n. Also, the algorithmutilizes very simple data structures that make it attrac-tive from an implementation viewpoint.

Our algorithm is a novel approach to combinatorialscaling algorithms. In the previous scaling algorithmsdeveloped by Edmonds and Karp, Rock 1980, andGabow, scaling involved a sequential approximationof either the cost coefficients or the capacities andright-hand sides. For example, we first solve the prob-lem with the costs C approximated by C/2T for someinteger T; we then reoptimize to solve the problemwith costs approximated by C/2T-, and then reopti-mize for the problem with costs approximated byC/2 - 2, and so forth. Our excess scaling algorithmdoes not fit into this standard framework. Rather, ouralgorithm works with true data, relaxes the flow con-servation constraints and scales the maximumamount of relaxation.

The preflow-push algorithms for the maximum flowproblem have been extended for the minimum costflow problem. A generalization of the Goldberg-Tarjan maximum flow algorithm to the minimumcost flow problem was developed by Bertsekas (1986).This algorithm, however, was only pseudopolynomial.Goldberg and Tajan (1987) incorporated cost scaling

-- " � W�IT PWMRMR,0-1��5`0 ,r-��, -ARGENTINA I-4 'O,

_ --- �------

Page 11: A FAST AND SIMPLE ALGORITHM FOR THE MAXIMUM FLOW …

758 / AHUJA AND ORLIN

in this approach and obtained a polynomial timealgorithm. The algorithm of Goldberg and Tarjan(1987) is similar to our algorithm-it also works withtrue data, relaxes the complementary slackness con-ditions and gradually decreases the relaxation to zero.

The scaling algorithm for the maximum flow prob-lem can be improved further by using more cleverrules to push flow or by using dynamic trees. Wedescribe such improvements in Ahuja, Orlin andTarjan. We show that by using a larger scale factorand by pushing flow from a node with the highestdistance label among nodes having sufficiently largeexcess, the algorithm runs in O(nm + n2log U/log logU) time. (Assume that U > 4.) We describe anothervariation of the excess scaling algorithm that runs inO(nm + n2 sJ/igT) time. Use of the dynamic treedata structure further improves the complexity of thisalgorithm to O(nm log(n igVU/m + 2)).

We also have undertaken an extensive empiricalstudy to assess the computational merits of thepreflow-push algorithms versus the previous bestalgorithms, those of Dinic and Karzanov. Our exper-iments so far suggest that preflow-push algorithms aresubstantially faster than Dinic's and Karzanov'salgorithms.

Our algorithms and those due to Goldberg andTarjan suggest the superiority of distance label basedapproaches over the layered network based ap-proaches. The improvements we obtain do not seemto be possible for the algorithms utilizing layerednetworks. The distance labels implicitly store dynam-ically changing layered networks and hence are morepowerful. We show the use of distance labels in aug-menting path algorithms, capacity scaling algorithmsand for unit capacity networks in Orlin and Ahuja(1987).

The maximum flow problem on bipartite networksis an important class of the maximum flow problem(see Gusfield, Martel and Fernandez-Baca 1985). Thebipartite network is a network G = (N, A), such thatN = N U N2 and A N x N 2 . Let n, = N, I andn2= IN2 1. For cases where n << n2, our maximumflow algorithm can be modified to run in O(nl m +n2 log U) time, thus resulting in significant speedupover the original algorithm. Our results on bipartitenetwork flows will appear in a future paper jointlywith C. Stein and R. Tarjan.

ACKNOWLEDGMENT

We wish to thank John Bartholdi, Tom Magnanti,and Hershel Safer for their suggestions which led toimprovements in the presentation. We also are grate-

ful to the referees for their perceptive comments. Thisresearch was supported in part by the PresidentialYoung Investigator Grant 8451517-ECS of theNational Science Foundation, by grant AFOSR-88.0088 from the Air Force Office of Scientific Research,and by grants from Analog Devices, Apple Computer,Inc., and Prime Computer.

REFERENCES

AHO, A. V., J. E. HOPCROFT AND J. D. ULLMAN. 1974.The Design and Analysis of Computer Algorithms.Addison-Wesley, Reading, Mass.

AHUJA, R. K., J. B. ORLIN AND R. E. TARJAN. 1988.Improved Time Bounds for the Maximum FlowProblem. Research Report, Sloan School of Man-agement, MIT, Cambridge, Mass. (to appear inSIAM J. Comp.).

BERTSEKAS, D. 1986. Distributed Relaxation Methods forLinear Network Flow Problems. Proc. of25th IEEEConference on Decision and Control, Athens, Greece.

CHERIYAN, J., AND S. N. MAHESHWARI. 1988. Analysisof Preflow Push Algorithms for Maximum NetworkFlow. Technical Report, Dept. of Computer Scienceand Engineering, Indian Institute of Technology,New Delhi, India. (Revised).

CHERKASKY, R. V. 1977. Algorithm for Construction ofMaximal Flow in Networks With Complexity ofO(V2'-E) Operation (in Russian). Math. MethodsSolution Econ. Prob. 7, 112-125.

DANTZIG, G. B., AND D. R. FULKERSON. 1956. On theMax-Flow Min-Cut Theorem of Networks. In Lin-ear Inequalities and Related Systems, pp. 215-221,H. W. Kuhn and A. W. Tucker (eds.) (Annals ofMathematics Study 38). Princeton University Press,Princeton, N.J.

DEKEL, E., AND S. SAHANI. 1983. Binary Trees andParallel Scheduling Algorithms. IEEE Trans.Comput. 10, 657-675.

DINIC, E. A. 1970. Algorithm for Solution of a Problemof Maximum Flow in Networks With Power Esti-mation. Soviet Math. Dokl. 11, 1277-1280.

EDMONDS, J., AND R. M. KARP. 1972. TheoreticalImprovements in Algorithmic Efficiency for Net-work Flow Problems. J. Assoc. Comput. Mach. 19,248-264.

FORD, L. R., AND D. R. FULKERSON. 1956. MaximalFlow Through a Network. Can. J. Math. 8,399-404.

FULKERSON, D. R., AND G. B. DANTZIG. 1955. Compu-tations of Maximum Flow in Networks. Naval Res.Log. Quart. 2, 277-283.

GABOW, H. N. 1985. Scaling Algorithms for NetworkProblems. J. Comput. Syst. Sci. 31, 148-168.

GALIL, Z. 1980. An O(V5 3 E2/3) Algorithm for the Max-imal Flow Problem. Acta Inform. 14, 221-242.

GALIL, Z. AND A. NAAMAD. 1980. An O(VE log2 V)

Algorithm foiComput. Syst.

GOLDBERG, A. V.Technical Rejfor Computer

GOLDBERG, A. V.Sequential an(tion, LaboratCambridge, vMIT/LCS/TR

GOLDBERG, A. V.,Approach to tIthe 18th Annlof Computing,Mach. 35 (198

GOLDBERG, A. V.,Minimum C(Approximatiolposium on the

GUSFIELD, D., C.1985. Fast AlgTechnical Refment of ComiHaven, Conn.

KARZANOV, A. V. Iin a NetworkMath. Dokl. 15

KINDERVATER, G.

lp 'mpl!IPl !1 I L a

ti

Il..

!, .i, · ' : I,. '

.:r ,t::li tiis- -tI- - I·~:?

,l -

Page 12: A FAST AND SIMPLE ALGORITHM FOR THE MAXIMUM FLOW …

... , - wpqlp b

comments. Thisthe Presidential17-ECS of therant AFOSR-88-ientific Research,apple Computer,

). ULLMAN. 1974.,puter Algorithms.

E. TARJAN. 1988.Maximum Flow

~ School of Man-;s. (to appear in

ation Methods for'roc. of 25th IEEE1, Athens, Greece.u. 1988. Analysisaximum Network:omputer Sciencee of Technology,

,r Construction ofh Complexity of). Math. Methods

ON. 1956. On the4etworks. In Lin-,ms, pp. 215-221,(eds.) (Annals ofUniversity Press,

linary Trees and. IEEE Trans.

tion of a ProblemWith Power Esti-77-1280.972. Theoretical-iciency for Net-qmput. Mach. 19,

1956. Maximalin. J. Math. 8,

o. 1955. Compu-vorks. Naval Res.

ims for Network., 148-168.thm for the Max-14, 221-242.\n O( VE log2 V)

I

Algorithm for the Maximum Flow Problem. J.Comput. Syst. Sci. 21, 203-217.

GOLDBERG, A. V. 1985. A New Max-Flow Algorithm.Technical Report MIT/LCS/TM-291, Laboratoryfor Computer Science, MIT, Cambridge, Mass.

GOLDBERG, A. V. 1987. Efficient Graph Algorithms forSequential and Parallel Computers. Ph.D. Disserta-tion, Laboratory for Computer Science, MIT,Cambridge, Mass. Available as Technical ReportMIT/LCS/TR-374.

GOLDBERG, A. V., AND R. E. TARJAN. 1986. A NewApproach to the Maximum Flow Problem. Proc. ofthe 18th Annual ACM Symposium on the Theoryof Computing, 136-146. (also in J. Assoc. Comput.Mach. 35 ( 1 988), 921-940).

GOLDBERG, A. V., AND R. E. TARJAN. 1987. SolvingMinimum Cost Flow Problem by SuccessiveApproximation. Proc. ofthe 19th AnnualACMSym-posium on the Theory of Computing, 7-18.

GUSFIELD, D., C. MARTEL AND D. FERNANDEZ-BACA.

1985. Fast Algorithms for Bipartite Network Flow.Technical Report YALEV/DCS/TR-356, Depart-ment of Computer Science, Yale University, NewHaven, Conn.

KARZANOV, A. V. 1974. Determining the Maximal Flowin a Network by the Method of Preflows. SovietMath. Dokl 15, 434-437.

KINDERVATER, G. A. P., AND J. K. LENSTRA. 1988.

Algorithm for the Maximum Flow Problem / 759

Parallel Computing in Combinatorial Optimization.Ann. Opns. Res. 14, 245-289.

MALHOTRA, V. M., M. P. KUMAR, AND S. N.MAHESHWARI. 1978. An O(f V13) Algorithm forFinding Maximum Flows in Networks. Inform.Process. Lett. 7, 277-278.

ORLIN, J. B., AND R. KI AHUJA. 1987. New Distance-Directed Algorithms for Maximum Flow and Para-metric Maximum Flow Problems. Working PaperNo. 1908-87, Sloan School of Management, MIT,Cambridge, Mass.

ROCK, H. 1980. Scaling Techniques for Minimal CostNetwork Flows. In Discrete Structures and Algo-rithms, pp. 181-191, V. Page and Carl Hanser (eds.)Miinchen, West Germany.

SHILOACH, Y. 1978. An O(nI log(I)) Maximum FlowAlgorithm. Technical Report STAN-CS-78-702,Computer Science Department, Stanford Univer-sity, Stanford, Calif.

SHILOACH, Y., AND U. VISHKIN. 1982. An O(n 2log n)Parallel Max-Flow Algorithm. J. Algorithms 3,128-146.

SLEATOR, D. D., AND R. E. TARJAN. 1983. A DataStructure for Dynamic Trees, J. Comput. Syst. Sci.24, 362-391.

TARJAN, R. E. 1984. A Simple Version of Karzanov'sBlocking Flow Algorithm. Opns. Res. Lett. 2,265-268.

A,.4I~~~~~~ ~