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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find if there is a path between two vertices in a directed graph
- Find the number of islands | Set 1 (Using DFS)
- Disjoint Set (Or Union-Find) | Set 1 (Detect Cycle in an Undirected Graph)
- Union-Find Algorithm | Set 2 (Union By Rank and Path Compression)
- Articulation Points (or Cut Vertices) in a Graph
- Ford-Fulkerson Algorithm for Maximum Flow Problem
- Maximum Bipartite Matching
- Find minimum s-t cut in a flow network
- Johnson's algorithm for All-pairs shortest paths
- Given a sorted dictionary of an alien language, find order of characters
- Find if an array of strings can be chained to form a circle | Set 1
- Tarjan's Algorithm to find Strongly Connected Components
- Boggle (Find all possible words in a board of characters) | Set 1
- Print all paths from a given source to a destination
- Optimal read list for given number of days
- Find the minimum cost to reach destination using a train
- Hopcroft–Karp Algorithm for Maximum Matching | Set 1 (Introduction)
- Find same contacts in a list of contacts
- Hopcroft–Karp Algorithm for Maximum Matching | Set 2 (Implementation)
- Number of Triangles in an Undirected Graph