Backtracking Lecture 4
Backtracking Lecture 4
EVEN 2022
Module 4: Lecture 4, 5
Design Technique: Backtracking
FORD-FULKERSON(G,s,t)
for each edge (u,v)E[G]
G
do f[u,v] 0
f[v,u] 0
while there exists a path p from s to t in the residual network G f
do cf(p) min{cf(u,v): (u,v) is in p}
for each edge (u,v) in p
do f[u,v] f[u,v]+cf(p) GR
• An augmenting path is a simple path from source to sink which do not include any cycles and that pass only
through positive weighted edges.
• A residual network graph (GR)indicates how much more flow is allowed in each edge in the network graph.
• For every edge in the augmenting path, a value of minimum capacity in the path is subtracted from all the
edges of that path.
• An edge of equal amount is added to edges in reverse direction for every successive nodes in the
augmenting path.
• If there are no augmenting paths possible from S to T, then the flow is maximum.
• The result i.e. the maximum flow will be the total flow out of source node which is also equal to total flow in to
the sink node.
12 4/12
16 v1 v3 20
4/16 v1 v3 20
10 4 t
s 9 s 10 4 7
4/9 t
13 4 13 4/4
v2 v4
v2 v4
14 4/14
8
12 4/12
v1 v3 20 v1 v3 7/20
4 11/16
4
s 4 4
10 t s 7/10 4 7/7
7 t
4/9
13 10 4 13 4/4
v2 v4 v2 v4
4 11/14
8 12/12
5 v1 v3 13 11/16 v1 v3 15/20
4
11 4
s 3 11 7 7 7/7
t s 10 1/4
4/9 t
5
13 3
4 8/13 4/4
v2 v4 v2 v4
11 11/14
12
12/12
5 v1 v3 5
11/16 v1 v3 19/20
11 4
15
s 11 3 7 7/7
t s 10 1/4
5 9 t
3
8 4 12/13 4/4
v2 v4 v2 v4
11 11/14 Total Flow = 23
Edmonds-Karp algorithm
• Implement the computation of the augmenting path p with a BFS
• Breadth-first search gives the shortest path for graphs (Assuming the length of each edge is 1.)
• Time complexity of Edmonds-Karp algorithm is O(VE2).
Source S A Shortest path is ADEG using BFS Shortest path is ADFG using BFS
Sink T G
Flow = 1 Flow = 1 + 2 = 3
• A cut(S,T) of flow network G=(V,E) is a partition of V into S and T=V-S such that
• The net flow across the cut(S,T) is defined to be f(S,T). The capacity of the cut(S,T) is c(S,T)
12/12
v1 v3
11/16 15/20
8/13 4/4
Max-flow min-cut theorem
v2 v4
11/14
S T