0% found this document useful (0 votes)
32 views10 pages

Backtracking Lecture 4

1. The document discusses network flow problems and algorithms to solve them, including Ford-Fulkerson and Edmonds-Karp algorithms. 2. It explains the concepts of augmenting paths, residual networks, and using BFS to find the shortest augmenting path. 3. It also covers max-flow min-cut theorem and how the minimum cut can be found from the residual graph after computing the maximum flow.

Uploaded by

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

Backtracking Lecture 4

1. The document discusses network flow problems and algorithms to solve them, including Ford-Fulkerson and Edmonds-Karp algorithms. 2. It explains the concepts of augmenting paths, residual networks, and using BFS to find the shortest augmenting path. 3. It also covers max-flow min-cut theorem and how the minimum cut can be found from the residual graph after computing the maximum flow.

Uploaded by

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

Algorithms and Problem Solving (15B11CI411)

EVEN 2022

Module 4: Lecture 4, 5
Design Technique: Backtracking

Jaypee Institute of Information Technology (JIIT)


A-10, Sector 62, Noida
Network Flow Problem
• Maximum flow problems involve finding a feasible flow
through a single-source, single-sink flow network that is
maximum. 
• In graph theory, a flow network is defined as a directed graph
involving a source(S) and a sink(T) and several other nodes
connected with edges.
• Each edge has an individual capacity which is the maximum
limit of flow that edge could allow.
• Flow in the network should follow the following conditions:
• For any non-source and non-sink node, the input flow is equal to output flow.
• For any edge(Ei) in the network, 0<= flow(Ei) <= Capacity(Ei)
• Total flow out of the source node is equal total to flow in to the sink node.
• Net flow in the edges follows skew symmetry i.e. F(u,v) = - F(u,v) where F(u,v) is flow from node u
to node v. This leads to a conclusion where you have to sum up all the flows between two
nodes(either directions) to find net flow between the nodes initially.
Time Complexity: O(max_flow * E)
Ford Fulkerson Algorithm Space complexity: O(E + V)

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

Continue to obtain maximum flow.


Cuts of flow networks

• 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

s 10 1/4 4/9 7/7


t

8/13 4/4
Max-flow min-cut theorem
v2 v4
11/14

S T

A cut (S,T), where S={s,v1,v2} and T={v3,v4,t}.


The net flow across (S,T) is f(S,T)=12-4+11=19
and the capacity is c(S,T)=12+14=26.
Min-cut problem
12/12
• In a flow network, the minimum cut separates the source 11/16
v1 v3
15/20
and sink vertices and minimizes the total sum of the
capacities of the edges that are directed from the source side 10 1/4 4/9 7/7
s t
of the cut to the sink side of the cut.
• Once you find the max flow, the minimum cut can be found 8/13
v2 v4 4/4
by creating the residual graph 11/14
• Traverse this residual network from the source to all
S T
reachable nodes, these nodes define one part of the
partition. Call this partition S.
• The rest of the nodes (the unreachable ones) can be called T.
• The size of the minimum cut is the sum of the weights of the
edges in the original network which flow from a node in S to
a node in T.
Bipartite Graph matching problem
• A matching in a Bipartite Graph is a set of the edges chosen in such a way that no two edges
share an endpoint.
• A maximum matching is a matching of maximum size (maximum number of edges).
• In a maximum matching, if any edge is added to it, it is no longer a matching. 
Example:
• There are M job applicants and N jobs.
• Each applicant has a subset of jobs that he/she is
interested in.
• Each job opening can only accept one applicant
and a job applicant can be appointed for only one
job.
• Find an assignment of jobs to applicants in such
that as many applicants as possible get jobs.
• Represent the Job assignment problem as Max-flow
problem
• Create a flow network
• Find Max-flow in the network
• The maximum flow is actually the MBP we are looking
for.

You might also like