Given a directed graph and two vertices in it, source ‘s’ and destination ‘t’, find out the maximum number of edge disjoint paths from s to t. Two paths are said edge disjoint if they don’t share any edge.
There can be maximum two edge disjoint paths from source 0 to destination 7 in the above graph. Two edge disjoint paths are highlighted below in red and blue colors are 0-2-6-7 and 0-3-6-5-7.
Note that the paths may be different, but the maximum number is same. For example, in the above diagram, another possible set of paths is 0-1-2-6-7 and 0-3-6-5-7 respectively.
This problem can be solved by reducing it to maximum flow problem. Following are steps.
1) Consider the given source and destination as source and sink in flow network. Assign unit capacity to each edge.
2) Run Ford-Fulkerson algorithm to find the maximum flow from source to sink.
3) The maximum flow is equal to the maximum number of edge-disjoint paths.
When we run Ford-Fulkerson, we reduce the capacity by a unit. Therefore, the edge can not be used again. So the maximum flow is equal to the maximum number of edge-disjoint paths.
Following is the implementation of the above algorithm. Most of the code is taken from here.
There can be maximum 2 edge-disjoint paths from 0 to 7
Time Complexity: Same as time complexity of Edmonds-Karp implementation of Ford-Fulkerson (See time complexity discussed here)
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Maximum Possible Edge Disjoint Spanning Tree From a Complete Graph
- Find two disjoint good sets of vertices in a given graph
- Calculate number of nodes between two vertices in an acyclic Graph by Disjoint Union method
- Maximize shortest path between given vertices by adding a single edge
- Count all possible paths between two vertices
- Find the maximum component size after addition of each edge to the graph
- Shortest paths from all vertices to a destination
- Paths to travel each nodes using each edge (Seven Bridges of Königsberg)
- Find the number of Islands | Set 2 (Using Disjoint Set)
- Find K vertices in the graph which are connected to at least one of remaining vertices
- Maximize the number of uncolored vertices appearing along the path from root vertex and the colored vertices
- Find the number of paths of length K in a directed graph
- Maximum and minimum isolated vertices in a graph
- Maximum cost path in an Undirected Graph such that no edge is visited twice in a row
- Maximum difference of count of black and white vertices in a path containing vertex V
- Disjoint Set (Or Union-Find) | Set 1 (Detect Cycle in an Undirected Graph)
- Maximum product of two non-intersecting paths in a tree
- Find weight of MST in a complete graph with edge-weights either 0 or 1
- Find if there is a path between two vertices in a directed graph
- Find if there is a path between two vertices in a directed graph | Set 2