The Maximum Network Flow Problem
The Maximum Network Flow Problem
The Maximum Network Flow Problem
• How can we maximize the flow in a network from a source or set of sources to a destination or
set of destinations?
• Find maximum flow in a flow network from a single source s to a single sink t
AUGMENTING PATH
Path from s to t in Gf
Residual capacity = smallest capacity of edges of p
• Classic Method:
– Repeat
Ford-Fulkerson Method
Example 1
Example 2
Example 4
A spanning tree of a graph is just a subgraph that contains all the vertices and is a tree. A graph
may have many spanning trees; for instance the complete graph on four vertices
・Connected.
・Acyclic.
The cost of the spanning tree is the sum of the weights of all the edges in the tree. There can be
many spanning trees. Minimum spanning tree is the spanning tree where the cost is minimum
among all the spanning trees. There also can be many minimum spanning trees.
There are two famous algorithms for finding the Minimum Spanning Tree
Kruskal’s Algorithm
Kruskal’s Algorithm builds the spanning tree by adding edges one by one into a growing spanning
tree. Kruskal's algorithm follows greedy approach as in each iteration it finds an edge which has
least weight and add it to the growing spanning tree.
Algorithm Steps:
Prim’s Algorithm
Prim’s Algorithm also use Greedy approach to find the minimum spanning tree. In Prim’s
Algorithm we grow the spanning tree from a starting position. Unlike an edge in Kruskal's, we
add vertex to the growing spanning tree in Prim's.
Algorithm Steps:
Maintain two disjoint sets of vertices. One containing vertices that are in the growing
spanning tree and other that are not in the growing spanning tree.
Select the cheapest vertex that is connected to the growing spanning tree and is not in
the growing spanning tree and add it into the growing spanning tree. This can be done
using Priority Queues. Insert the vertices, that are connected to growing spanning tree,
into the Priority Queue.
Check for cycles. To do that, mark the nodes which have been already selected and insert
only those nodes in the Priority Queue that are not marked.
In Prim’s Algorithm, we will start with an arbitrary node (it doesn’t matter which one) and mark it.
In each iteration we will mark a new vertex that is adjacent to the one that we have already
marked. As a greedy algorithm, Prim’s algorithm will select the cheapest edge and mark the
vertex. So we will simply choose the edge with weight 1. In the next iteration we have three
options, edges with weight 2, 3 and 4. So, we will select the edge with weight 2 and mark the
vertex. Now again we have three options, edges with weight 3, 4 and 5. But we can’t choose edge
with weight 3 as it is creating a cycle. So we will select the edge with weight 4 and we end up with
the minimum spanning tree of total cost 7 ( = 1 + 2 +4).
・Dithering.
・Cluster analysis.
SOURCE:
https://www.hackerearth.com/practice/algorithms/graphs/minimum-spanning-tree/tutorial/
Exercise:
Answer: