Seminar 8 - Network Flow (Handout)
Seminar 8 - Network Flow (Handout)
Rafael Dowsley
28 April 2025
Agenda
2 Ford-Fulkerson method
3
a c
3 3
s t
3
5 5
b d
5
I Each edge has a given non-negative capacity (usually integers) giving the
maximum amount/rate of flow that the edge can carry.
1/51
What are flow networks used for?
3
a c
3 3
s t
3
5 5
b d
5
2/51
Flow
3/3
a c 0/
3
3/ 3
s t
3
3/
2/
5 5/5
b d
5/5
I Let Ein (v ) denote the set of all incoming edges to a vertex v , and similarly
Eout (v ) denote its set of outgoing edges.
I The total amount flowing into any vertex (through incoming edges) is equal
to the total amount flowing out of that vertex (through outgoing edges).
3/51
Quiz time!
Properties of a flow network
Capacity constraint
For every edge e, its flow is bounded by its capacity: 0 ≤ f (e) ≤ c(e).
Flow conservation
For every vertex v ∈ V \ {s, t}, it holds that
X X
f (ein ) = f (eout )
ein ∈Ein (v ) eout ∈Eout (v )
4/51
Flow of the network
3/3 12/12
a c 0/3 a c 15/
3/3 16
11/ 20
• Given that the flow network satisfies the capacity constraint and
flow conservation properties, the flow of the network is the total flow
out of the source vertex.
I Equivalently, this is the same as the total flow into sink vertex.
5/51
Maximum-flow problem
3/3 12/12
a c 0/3 a c 15/
3/3 16
11/ 20
Maximum-flow problem
Given a flow network, determine the maximum value of the flow that
can be sent from source s to sink t without violating the capacity
constraint and flow conservation properties.
6/51
Ford-Fulkerson method
Ford-Fulkerson method
7/51
Ford-Fulkerson intuition
0/3
a c 0/
3
0/ 3
s t
3
0/
0/
5 0/5
b d
0/5
8/51
Quiz time!
Ford-Fulkerson intuition
0/3
a c 0/
3
0/ 3
s t
3
0/
0/
5 0/5
b d
0/5
9/51
Ford-Fulkerson intuition
3/3
a c 0/
3
3/ 3
s t
3
3/
2/
5 5/5
b d
5/5
10/51
Quiz time!
Ford-Fulkerson intuition
3/3
a c 0/
3
3/ 3
s t
3
3/
2/
5 5/5
b d
5/5
We can! But there is no path from source to sink with spare capacity. . .
11/51
Ford-Fulkerson intuition
3/3
a c 3/
3
3/ 3
s t
3
0/
2/
5 5/5
b d
5/5
12/51
Ford-Fulkerson intuition
3/3
a c 3/
3
3/ 3
s t
3
0/
5/
5 5/5
b d
5/5
13/51
What actually happened here?
3/3
a c 3/
3
3/ 3
s t
3
0/
5/
5 5/5
b d
5/5
14/51
Residual network
3
1 4
2/ 2/ 5
5 4/ 3 4 1
b d b d
4/5
1
15/51
Augmenting path
3
1 4
2/ 2/ 5
5 4/ 3 4 1
b d b d
4/5
1
16/51
Ford-Fulkerson method
Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f
s t s t
3
3
0/
0/ 5
5 0/ 5 5
b d b d
0/5
5
17/51
Ford-Fulkerson method
Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f
s t s t
3
3
0/
0/ 5
5 0/ 5 5
b d b d
0/5
5
18/51
Ford-Fulkerson method
Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f
s t s t
3
3
3/
0/ 5
5 3/ 5 5
b d b d
3/5
5
19/51
Ford-Fulkerson method
Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f
3
3/
0/ 5
5 3/ 5 3 2
b d b d
3/5
2
20/51
Ford-Fulkerson method
Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f
3
3/
0/ 5
5 3/ 5 3 2
b d b d
3/5
2
21/51
Ford-Fulkerson method
Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f
3
0/
3/ 5
5 3/ 5 3 2
b d b d
3/5
2
22/51
Ford-Fulkerson method
Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f
3 3
0/
3/ 5
5 3/ 2 3 2
b d b d
3/5
2
23/51
Ford-Fulkerson method
Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f
3 3
0/
3/ 5
5 3/ 2 3 2
b d b d
3/5
2
24/51
Ford-Fulkerson method
Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f
3 3
0/
5/ 5
5 5/ 2 3 2
b d b d
5/5
2
25/51
Ford-Fulkerson method
Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f
3 5
0/
5/ 5
5 5/ 5
b d b d
5/5
26/51
Ford-Fulkerson method
Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f
3 5
0/
5/ 5
5 5/ 5
b d b d
5/5
27/51
Implementation details
• Edge “type” in the residual does not matter as we can send flow
along any of them.
I Forward edges can have flow sent along them because they have spare
capacity.
I Backward edges can have flow sent along them because reducing a flow in
one direction is the same as increasing the flow in the opposite direction.
28/51
Quiz time!
Implementation details
x x
a/b c/d (b − a) + c (d − c) + a
y y
29/51
Time complexity
Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f
• Updating the residual: two edges per edge of the augmenting path, so O(|V |).
• Total work in one iteration of the loop: O(|V | + |E |) = O(|E |) as the graph is
connected.
30/51
Time complexity
Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f
31/51
Quiz time!
Time complexity
Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f
32/51
Time complexity
Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f
• It can be proven that the complexity is O(|V | · |E |2 ) when using BFS to find
augmenting paths, which is polynomial.
33/51
Correctness
Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f
• In order to show that the algorithm terminates exactly once it finds a flow whose
value is the maximum possible value among all feasible flows, we will need to
study the Min-cut Max-flow Theorem.
34/51
Min-cut Max-flow Theorem
Cut
12/12
6 a c 15/
1 1/1 20
• The cut-set of a cut (S,T ) is the set of edges that “cross” the cut,
i.e., each edge connects one vertex in S with another in T .
35/51
Flow and capacity of a cut
12/12
a c 15/
16
11/ 20
• Note that the flow of a cut is always ≤ to the capacity of the cut.
I Flow of an edge ≤ capacity of an edge.
I Capacity of a cut does not subtract capacities for incoming edges.
36/51
Flow and capacity of a cut
12/12
a c 15/
16
11/ 20
37/51
Another cut
12/12
a c 15/
16
11/ 20
38/51
Yet another cut
12/12
a c 15/
16
11/ 20
39/51
Are the flows of every cut the same?
12/12
a c 15/
16
11/ 20
• It seems that the flow of every cut is the same, let’s prove this!
• Let Fout (v ) denote the total flow going out of vertex v and Fin (v )
denote the total flow coming into vertex v .
12/12
a c 15/
16
11/ 20
X
Fout (s) = Fout (s) + (Fout (v ) − Fin (v ))
v ∈S\s
X
= (Fout (v ) − Fin (v ))
v ∈S
X
= (Fout (v ) + Fout (v ) − Fin (v ) − Fin (v ))
v ∈S
1st equation: by flow conservation, 2nd equation: as source has no incoming edges and
so Fin (s) = 0, 3rd equation: just separates the flow through red and green arrows.
41/51
Flow of every cut is the same
12/12
a c 15/
16
11/ 20
X
Fout (s) = (Fout (v ) + Fout (v ) − Fin (v ) − Fin (v ))
v ∈S
X X
= (Fout (v ) − Fin (v )) + (Fout (v ) − Fin (v ))
v ∈S v ∈S
X
= (Fout (v ) − Fin (v ))
v ∈S
The last equation follows from the fact that each red edge appears once as an incoming
edge and once as an outgoing edge.
42/51
Flow of every cut is the same
12/12
a c 15/
16
11/ 20
X
Fout (s) = (Fout (v ) − Fin (v ))
v ∈S
We conclude that the flow of any cut is equal to the flow of the network.
43/51
Min-cut
• What if we can find a pair of flow and cut such that the flow of the
network = capacity of the cut?
I The flow value cannot be increased any further as it would violate the
capacity of that cut, so it is the maximum flow.
I The cut is a min-cut of the flow network.
44/51
Min-cut Max-flow Theorem
45/51
Proof of correctness
3
3 5
5/
6 0/ 5/
6 1 5 1
b d b d
5/5
46/51
Proof of correctness
3
3 5
5/
6 0/ 5/
6 1 5 1
b d b d
5/5
I For each outgoing edge, e.g., a → c, its flow is equal to the capacity of the
edge. Otherwise, edge a → c would be in the residual network and c would
be reachable from s (but we know this is not the case as c 6∈ S).
I For each incoming edge, e.g., c → b, its flow is zero. Otherwise, there
would be an edge b → c in the residual network implying c is reachable
from s (but we know this is not the case as c 6∈ S).
47/51
Min-cut max-flow connection used in practice
48/51
Min-cut max-flow connection used in practice
49/51
Reading
• You can also check algorithms’ textbooks for contents related to this
lecture, e.g.:
50/51
Concluding remarks
51/51