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