UMass Lowell Computer Science 91.503
Analysis of Algorithms
Prof. Karen Daniels
Fall, 2006
Lecture 5
Wednesday, 10/4/06
Graph Algorithms: Part 2
Network Flow
Chapter 26
Basic Network Flow Concepts
Network Flow
edge weights
2
3
1
source
Goal: compute second set of
edge weights <= capacities.
1
1
3
2
3
weighted network
sink
flow in = flow out
(except at source, sink)
flow
direction
source: Sedgewick, Graph Algorithms
Network Flow Applications
• Distribution Problems
• move objects from place to place within network
• examples:
• merchandise
• communications
• traffic flow
source: Sedgewick, Graph Algorithms
Network Flow Applications
(continued)
• Matching Problems
• network represents ways to connect vertices
• goal: choose connections to
• cover vertex set
• only touch each vertex once
• examples:
• job placement
• minimum-distance point matching (2 point sets)
source: Sedgewick, Graph Algorithms
Network Flow Applications
(continued)
• Cut Problems
• remove edges to cut network into >= 2 pieces
• examples:
• network reliability
• cutting supply lines
source: Sedgewick, Graph Algorithms
Flow Definitions
• Flow network G = (V, E)
capacity
• directed graph
• each edge (u,v) in E has capacity
c(u,v) >= 0
• every vertex is on some path from
source s to sink t
2
3
1
1
1
3
2
3
• G is connected
• |E| >= |V| - 1
source: 91.503 textbook Cormen et al.
Flow Properties
• Flow in G is f: VxV -> R satisfying:
• Capacity Constraint: u, v V
• Skew Symmetry:
u, v V
• Flow Conservation:
f (u, v) f (v, u )
vV
uV
u V {s, t}
f (u, v) c(u, v)
f (u, v) 0 v V {s, t}
• f (u,v) is net flow from vertex u to vertex v
• positive flow entering vertex v:
uV
f ( u ,v ) 0
f (u, v) 0
f (u, v)
• positive flow entering a vertex other than source or sink must =
positive flow leaving the vertex
• Value of a flow f is total net flow out of source:
| f | vV f ( s, v)
source: 91.503 textbook Cormen et al.
Flow Properties (continued)
•
Lemma 26.1
•
Let G=(V, E) be a flow network, and let f be a flow
in G. Then: X V f ( X , X ) 0
X , Y V f ( X , Y ) f (Y , X )
X , Y , Z V with X Y 0 f ( X Y , Z ) f ( X , Z ) f (Y , Z )
X , Y , Z V with X Y 0 f ( Z , X Y ) f ( Z , X ) f ( Z , Y )
•
Implicit summation notation: f ( X , Y )
f ( x, y)
xX yY
Exercise: show | f | f (V , t )
source: 91.503 textbook Cormen et al.
Flow Properties (continued)
Flow Equilibrium
D = amount of
flow out of
right set (and
B = amount of
flow out of left
set (and not into
not into left set)
right set)
A = amount of
flow into left set
from outside
right set
C = amount
of flow into
right set from
outside left
set
y = amount of
flow into right
set from left
set
x = amount
of flow into
left set from
right set
EQUILIBRIUM requires
A+x=B+y
C+y=D+x
A+C=B+D
source: Sedgewick, Graph Algorithms
Controlling Network Flow
open switches along path < 0,1,3,5>
open switches along path < 0,2,4,5>
3 leave s
2 leave s
2 flow into t
3 flow into t
reduce by 1
increase by 1
change switch at 1 to
redirect flow to fill 1-4;
add flow on < 0,2,3,5 >
(maxflow results)
source: Sedgewick, Graph Algorithms
Augmenting Paths
Augmenting Flow on a Path
2
2
1
1
2
2
increase flow in <0,2> increase flow in <2,3>
decrease flow in <1,3>
flow increases from 3 to 4
1
1
2
increase flow on <1,4>,<4,5>
source: Sedgewick, Graph Algorithms
Augmenting Path Sequences
Try #1
Strategy: Keep trying until no
augmenting path can be found.
Same max flow in each case
although strategy is greedy!
To show strategy always
produces max flow,
3 key ideas:
1) augmenting paths
2) residual networks
3) cuts
Try #2
source: Sedgewick, Graph Algorithms
Try #3
Residual Networks
Residual Networks
min capacity on
augmenting path
residual capacity
flow
network G
and flow f
residual
network Gf
and
augmenting
path
flow = amount
we can remove
augmented
flow in Gf
augmented
flow in G
26.3
26.1
(no 0 edges are shown)
source: 91.503 textbook Cormen et al.
Cuts
s-t Cut
Disconnects source from sink
source: Sedgewick, Graph Algorithms
s-t Cut
“Negative” flow edges are excluded from cut capacity.
c(S,T)=29
c(S,T)=26
c(S,T)=24
Minimum cut is cut (S,T) whose capacity is minimum over all s-t cuts of network.
source: 91.503 textbook Cormen et al.
MaxFlow MinCut Theorem
•
If f is a flow in a flow network G=(V, E)
with source s and sink t, then, equivalently:
•
•
•
1. f is a maximum flow in G
2. The residual network Gf contains no
augmenting paths
3. | f | = c(S,T) for some cut (S,T) of G
source: 91.503 textbook Cormen et al.
MaxFlow MinCut Theorem
Proof Layout
Lemma 26.1
Lemma 26.3
Eq 26.6
Lemma 26.5
(2) -> (3)
Lemma 26.2
Eq 26.4
Corollary 26.4
(1) -> (2)
(3) -> (1) Corollary 26.6
MaxFlow MinCut
Theorem 26.7
Ford-Fulkerson MaxFlow Method
General Approach
source: 91.503 textbook Cormen et al.
With Residual Networks
f (u, v) f [u, v] if (u, v) E or (v, u ) E
f (u, v) f [u, v] if (u, v) E or (v, u ) E
f (u, v) f [u, v] if (u, v) E or (v, u ) E
f [u, v] is undefined if neither (u, v) E nor (v, u ) E
source: 91.503 textbook Cormen et al.
source: 91.503 textbook Cormen et al.
Analysis
Q(|E|) time
Time depends
on method
termination?
O( |max f | )
iterations,
assuming integral
capacities
Each iteration of while loop can be executed in O(|E|)
time = time to find path in residual network using BFS or DFS
Total time = O( |E| |max f | ) assuming integral capacities
source: 91.503 textbook Cormen et al.
Shortest Augmenting Paths
Edmonds-Karp
source: Sedgewick, Graph Algorithms
Shortest Augmenting Paths
Edmonds-Karp
• Time is in O(|V||E|2):
• Each iteration of while loop takes time in O(|E|)
• Number of iterations is in O(|V||E|)
• Shortest-path distance in residual network increases
monotonically with each flow augmentation
• Total number of augmentations is in O(|V||E|)
• Proof Sketch:
• Edge in residual network is critical on augmenting path if
residual capacity of path is residual capacity of (u,v)
• Critical edge disappears from residual network
• Critical edge reappears only if net flow from u to v is
decreased; happens only if (v,u) appears later on another
augmenting path
• From time (u,v) becomes critical to time it next becomes
critical, distance of u from source increases by >= 2
• (u,v) becomes critical at most O(|V|) times
© Copyright 2026 Paperzz