# Check if removing a given edge disconnects a graph

Given an undirected graph and an edge, the task is to find if the given edge is a bridge in graph, i.e., removing the edge disconnects the graph.

Following are some example graphs with bridges highlighted with red color.

## Recommended: Please solve it on “PRACTICE” first, before moving on to the solution.

One solution is to find all bridges in given graph and then check if given edge is a bridge or not.

A simpler solution is to remove the edge, check if graph remains connect after removal or not, finally add the edge back. We can always find if an undirected is connected or not by finding all reachable vertices from any vertex. If count of reachable vertices is equal to number of vertices in graph, then the graph is connected else not. We can find all reachable vertices either using BFS or DFS. Below are complete steps.

1) Remove the given edge
2) Find all reachable vertices from any vertex. We have chosen first vertex in below implementation.
3) If count of reachable nodes is V, then return false [given is not Bridge]. Else return yes.

Output :
Yes

Time Complexity : O(V + E)

This article is contributed by Pankaj Sharma. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.