Java Program to Find Minimum Number of Edges to Cut to Make the Graph Disconnected
Given a connected graph, the task is to find the minimum number of edges to cut/remove to make the given graph disconnected.
A graph is disconnected if there exists at least two vertices of the graph that are not connected by a path.
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
Output: Minimum Number of Edges to Remove = 2
The approach to this problem is to find the number of paths in the edge disjoint set of paths from a start vertex to an end vertex in the graph. Edge-disjoint set of paths is a set of paths having no common edge between any two paths.
- Pick one node as start node and another node as end node.
- Start BFS from the start node and check if a path exists from start node to end node.
- If yes, then remove all the edges from that path and run BFS again.
- Repeat step 2 and 3 until there’s no path exists from start node to end node.
- Return the number of times a path is deleted.
Explanation with example:
Minimum Number of Edges to Remove = 2