0% found this document useful (0 votes)
2 views35 pages

Lecture 21

Uploaded by

erterek23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views35 pages

Lecture 21

Uploaded by

erterek23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Introduction to Algorithms

6.046J/18.401J
LECTURE 21
Network Flow II
• Max-flow, min-cut theorem
• Ford-Fulkerson algorithm
and analysis
• Edmonds-Karp algorithm
and analysis
• Best algorithms to date

Prof. Charles E. Leiserson


Recall from Lecture 22
• Flow value: | f | = f (s, V).
• Cut: Any partition (S, T) of V such that s ∈ S
and t ∈ T.
• Lemma. | f | = f (S, T) for any cut (S, T).
• Corollary. | f | ≤ c(S, T) for any cut (S, T).
• Residual graph: The graph Gf = (V, Ef ) with
strictly positive residual capacities cf (u, v) =
c(u, v) – f (u, v) > 0.
• Augmenting path: Any path from s to t in Gf .
• Residual capacity of an augmenting path:
c f ( p) = min {c f (u , v)} .
(u ,v )∈p
© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.2
Max-flow, min-cut theorem
Theorem. The following are equivalent:
1. | f | = c(S, T) for some cut (S, T).
2. f is a maximum flow.
3. f admits no augmenting paths.

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.3


Max-flow, min-cut theorem
Theorem. The following are equivalent:
1. | f | = c(S, T) for some cut (S, T).
2. f is a maximum flow.
3. f admits no augmenting paths.
Proof.
(1) ⇒ (2): Since | f | ≤ c(S, T) for any cut (S, T) (by
the corollary from Lecture 22), the assumption that
| f | = c(S, T) implies that f is a maximum flow.

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.4


Max-flow, min-cut theorem
Theorem. The following are equivalent:
1. | f | = c(S, T) for some cut (S, T).
2. f is a maximum flow.
3. f admits no augmenting paths.
Proof.
(1) ⇒ (2): Since | f | ≤ c(S, T) for any cut (S, T) (by
the corollary from Lecture 22), the assumption that
| f | = c(S, T) implies that f is a maximum flow.
(2) ⇒ (3): If there were an augmenting path, the
flow value could be increased, contradicting the
maximality of f.
© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.5
Proof (continued)
(3) ⇒ (1): Suppose that f admits no augmenting paths.
Define S = {v ∈ V : there exists a path in Gf from s to v},
and let T = V – S. Observe that s ∈ S and t ∈ T, and thus
(S, T) is a cut. Consider any vertices u ∈ S and v ∈ T.

ss uu vv
path in Gf S T
We must have cf (u, v) = 0, since if cf (u, v) > 0, then v ∈ S,
not v ∈ T as assumed. Thus, f (u, v) = c(u, v), since cf (u, v)
= c(u, v) – f (u, v). Summing over all u ∈ S and v ∈ T
yields f (S, T) = c(S, T), and since | f | = f (S, T), the theorem
follows.
© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.6
Ford-Fulkerson max-flow
algorithm
Algorithm:
f [u, v] ← 0 for all u, v ∈ V
while an augmenting path p in G wrt f exists
do augment f by cf (p)

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.7


Ford-Fulkerson max-flow
algorithm
Algorithm:
f [u, v] ← 0 for all u, v ∈ V
while an augmenting path p in G wrt f exists
do augment f by cf (p)
Can be slow:
109 109

G: ss 1 tt

109 109

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.8


Ford-Fulkerson max-flow
algorithm
Algorithm:
f [u, v] ← 0 for all u, v ∈ V
while an augmenting path p in G wrt f exists
do augment f by cf (p)
Can be slow:
0:109 0:109

G: ss 0:1 tt

0:109 0:109

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.9


Ford-Fulkerson max-flow
algorithm
Algorithm:
f [u, v] ← 0 for all u, v ∈ V
while an augmenting path p in G wrt f exists
do augment f by cf (p)
Can be slow:
0:109 0:109

G: ss 0:1 tt

0:109 0:109

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.10


Ford-Fulkerson max-flow
algorithm
Algorithm:
f [u, v] ← 0 for all u, v ∈ V
while an augmenting path p in G wrt f exists
do augment f by cf (p)
Can be slow:
1:109 0:109

G: ss 1:1 tt

0:109 1:109

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.11


Ford-Fulkerson max-flow
algorithm
Algorithm:
f [u, v] ← 0 for all u, v ∈ V
while an augmenting path p in G wrt f exists
do augment f by cf (p)
Can be slow:
1:109 0:109

G: ss 1:1 tt

0:109 1:109

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.12


Ford-Fulkerson max-flow
algorithm
Algorithm:
f [u, v] ← 0 for all u, v ∈ V
while an augmenting path p in G wrt f exists
do augment f by cf (p)
Can be slow:
1:109 1:109

G: ss 0:1 tt

1:109 1:109

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.13


Ford-Fulkerson max-flow
algorithm
Algorithm:
f [u, v] ← 0 for all u, v ∈ V
while an augmenting path p in G wrt f exists
do augment f by cf (p)
Can be slow:
1:109 1:109

G: ss 0:1 tt

1:109 1:109

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.14


Ford-Fulkerson max-flow
algorithm
Algorithm:
f [u, v] ← 0 for all u, v ∈ V
while an augmenting path p in G wrt f exists
do augment f by cf (p)
Can be slow:
2:109 1:109

G: ss 1:1 tt

1:109 2:109

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.15


Ford-Fulkerson max-flow
algorithm
Algorithm:
f [u, v] ← 0 for all u, v ∈ V
while an augmenting path p in G wrt f exists
do augment f by cf (p)
Can be slow:
2:109 1:109

G: ss 1:1 tt

1:109 2:109

2 billion iterations on a graph with 4 vertices!


© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.16
Edmonds-Karp algorithm
Edmonds and Karp noticed that many people’s
implementations of Ford-Fulkerson augment along
a breadth-first augmenting path: a shortest path in
Gf from s to t where each edge has weight 1. These
implementations would always run relatively fast.
Since a breadth-first augmenting path can be found
in O(E) time, their analysis, which provided the first
polynomial-time bound on maximum flow, focuses
on bounding the number of flow augmentations.
(In independent work, Dinic also gave polynomial-
time bounds.)
© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.17
Monotonicity lemma
Lemma. Let δ(v) = δf (s, v) be the breadth-first
distance from s to v in Gf . During the Edmonds-
Karp algorithm, δ(v) increases monotonically.

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.18


Monotonicity lemma
Lemma. Let δ(v) = δf (s, v) be the breadth-first
distance from s to v in Gf . During the Edmonds-
Karp algorithm, δ(v) increases monotonically.
Proof. Suppose that augmenting a flow f on G produces
a new flow f ′. Let δ′(v) = δf ′(s, v). We’ll show δ′(v) ≥
δ(v) by induction on δ′(v). For the base case, δ′(v) = 0
implies v = s, and since δ(s) = 0, we have δ′(v) ≥ δ(v).
For the inductive case, consider a breadth-first path s →
L → u → v in Gf ′. We must have δ′(v) = δ′(u) + 1, since
subpaths of shortest paths are shortest paths. Hence, we
have δ′(u) ≥ δ(u) by induction, because δ′(v) > δ′(u).
Certainly, (u, v) ∈ Ef ′.
© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.19
Proof of Monotonicity Lemma —
Case 1
Consider two cases depending on whether (u, v) ∈ Ef .

Case 1: (u, v) ∈ Ef .
We have
δ(v) ≤ δ(u) + 1 (triangle inequality)
≤ δ′(u) + 1 (induction)
= δ′(v) (breadth-first path),
and thus monotonicity of δ(v) is established.

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.20


Proof of Monotonicity Lemma —
Case 2
Case: (u, v) ∉ Ef .
Since (u, v) ∈ Ef ′ , the augmenting path p that produced
f ′ from f must have included (v, u). Moreover, p is a
breadth-first path in Gf :
p=s→L→v→u→L→t.
Thus, we have
δ(v) = δ(u) – 1 (breadth-first path)
≤ δ′(u) – 1 (induction)
= δ′(v) – 2 (breadth-first path)
< δ′(v) ,
thereby establishing monotonicity for this case, too.
© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.21
Counting flow augmentations
Theorem. The number of flow augmentations
in the Edmonds-Karp algorithm (Ford-Fulkerson
with breadth-first augmenting paths) is O(V E).

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.22


Counting flow augmentations
Theorem. The number of flow augmentations
in the Edmonds-Karp algorithm (Ford-Fulkerson
with breadth-first augmenting paths) is O(V E).
Proof. Let p be an augmenting path, and suppose that
we have cf (u, v) = cf (p) for edge (u, v) ∈ p. Then, we
say that (u, v) is critical, and it disappears from the
residual graph after flow augmentation.

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.23


Counting flow augmentations
Theorem. The number of flow augmentations
in the Edmonds-Karp algorithm (Ford-Fulkerson
with breadth-first augmenting paths) is O(V E).
Proof. Let p be an augmenting path, and suppose that
we have cf (u, v) = cf (p) for edge (u, v) ∈ p. Then, we
say that (u, v) is critical, and it disappears from the
residual graph after flow augmentation.
Example: cf (p) = 2
2 4 7 2 3
Gf : ss tt
3 2 1 2
© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.24
Counting flow augmentations
(continued)
The first time an edge (u, v) is critical, we have δ(v) =
δ(u) + 1, since p is a breadth-first path. We must wait
until (v, u) is on an augmenting path before (u, v) can
be critical again. Let δ′ be the distance function when
(v, u) is on an augmenting path. Then, we have
δ′(u) = δ′(v) + 1 (breadth-first path)
≥ δ(v) + 1 (monotonicity)
= δ(u) + 2 (breadth-first path).

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.25


Counting flow augmentations
(continued)
The first time an edge (u, v) is critical, we have δ(v) =
δ(u) + 1, since p is a breadth-first path. We must wait
until (v, u) is on an augmenting path before (u, v) can
be critical again. Let δ′ be the distance function when
(v, u) is on an augmenting path. Then, we have
δ′(u) = δ′(v) + 1 (breadth-first path)
≥ δ(v) + 1 (monotonicity)
= δ(u) + 2 (breadth-first path).
Example: uu
ss tt
vv
© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.26
Counting flow augmentations
(continued)
The first time an edge (u, v) is critical, we have δ(v) =
δ(u) + 1, since p is a breadth-first path. We must wait
until (v, u) is on an augmenting path before (u, v) can
be critical again. Let δ′ be the distance function when
(v, u) is on an augmenting path. Then, we have
δ′(u) = δ′(v) + 1 (breadth-first path)
≥ δ(v) + 1 (monotonicity)
= δ(u) + 2 (breadth-first path).
Example: δ(u) = 5
uu
ss tt
vv
δ(v) = 6
© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.27
Counting flow augmentations
(continued)
The first time an edge (u, v) is critical, we have δ(v) =
δ(u) + 1, since p is a breadth-first path. We must wait
until (v, u) is on an augmenting path before (u, v) can
be critical again. Let δ′ be the distance function when
(v, u) is on an augmenting path. Then, we have
δ′(u) = δ′(v) + 1 (breadth-first path)
≥ δ(v) + 1 (monotonicity)
= δ(u) + 2 (breadth-first path).
Example: δ(u) = 5
uu
ss tt
vv
δ(v) = 6
© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.28
Counting flow augmentations
(continued)
The first time an edge (u, v) is critical, we have δ(v) =
δ(u) + 1, since p is a breadth-first path. We must wait
until (v, u) is on an augmenting path before (u, v) can
be critical again. Let δ′ be the distance function when
(v, u) is on an augmenting path. Then, we have
δ′(u) = δ′(v) + 1 (breadth-first path)
≥ δ(v) + 1 (monotonicity)
= δ(u) + 2 (breadth-first path).
Example: δ(u) ≥ 7
uu
ss tt
vv
δ(v) ≥ 6
© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.29
Counting flow augmentations
(continued)
The first time an edge (u, v) is critical, we have δ(v) =
δ(u) + 1, since p is a breadth-first path. We must wait
until (v, u) is on an augmenting path before (u, v) can
be critical again. Let δ′ be the distance function when
(v, u) is on an augmenting path. Then, we have
δ′(u) = δ′(v) + 1 (breadth-first path)
≥ δ(v) + 1 (monotonicity)
= δ(u) + 2 (breadth-first path).
Example: δ(u) ≥ 7
uu
ss tt
vv
δ(v) ≥ 6
© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.30
Counting flow augmentations
(continued)
The first time an edge (u, v) is critical, we have δ(v) =
δ(u) + 1, since p is a breadth-first path. We must wait
until (v, u) is on an augmenting path before (u, v) can
be critical again. Let δ′ be the distance function when
(v, u) is on an augmenting path. Then, we have
δ′(u) = δ′(v) + 1 (breadth-first path)
≥ δ(v) + 1 (monotonicity)
= δ(u) + 2 (breadth-first path).
Example: δ(u) ≥ 7
uu
ss tt
vv
δ(v) ≥ 8
© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.31
Running time of Edmonds-
Karp
Distances start out nonnegative, never decrease, and are
at most |V| – 1 until the vertex becomes unreachable.
Thus, (u, v) occurs as a critical edge O(V) times, because
δ(v) increases by at least 2 between occurrences. Since
the residual graph contains O(E) edges, the number of
flow augmentations is O(V E).

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.32


Running time of Edmonds-
Karp
Distances start out nonnegative, never decrease, and are
at most |V| – 1 until the vertex becomes unreachable.
Thus, (u, v) occurs as a critical edge O(V) times, because
δ(v) increases by at least 2 between occurrences. Since
the residual graph contains O(E) edges, the number of
flow augmentations is O(V E).

Corollary. The Edmonds-Karp maximum-flow


algorithm runs in O(V E 2) time.

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.33


Running time of Edmonds-
Karp
Distances start out nonnegative, never decrease, and are
at most |V| – 1 until the vertex becomes unreachable.
Thus, (u, v) occurs as a critical edge O(V) times, because
δ(v) increases by at least 2 between occurrences. Since
the residual graph contains O(E) edges, the number of
flow augmentations is O(V E).

Corollary. The Edmonds-Karp maximum-flow


algorithm runs in O(V E 2) time.
Proof. Breadth-first search runs in O(E) time, and all
other bookkeeping is O(V) per augmentation.

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.34


Best to date
• The asymptotically fastest algorithm to date for
maximum flow, due to King, Rao, and Tarjan,
runs in O(V E logE/(V lg V)V) time.
• If we allow running times as a function of edge
weights, the fastest algorithm for maximum
flow, due to Goldberg and Rao, runs in time
O(min{V 2/3, E 1/2} ⋅ E lg (V 2/E + 2) ⋅ lg C),
where C is the maximum capacity of any edge
in the graph.

© 2001–4 by Charles E. Leiserson Introduction to Algorithms November 29, 2004 L21.35

You might also like