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.
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
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections 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.