Check if a given Graph is 2-edge connected or not
Given an undirected graph G, with V vertices and E edges, the task is to check whether the graph is 2-edge connected or not. A graph is said to be 2-edge connected if, on removing any edge of the graph, it still remains connected, i.e. it contains no Bridges.
Input: V = 7, E = 9
Given any vertex in the graph, we can reach any other vertex in the graph. Moreover, removing any edge from the graph does not affect its connectivity. So, the graph is said to be 2-edge connected.
Input: V = 8, E = 9
On removal of the edge between vertex 3 and vertex 4, the graph is not connected anymore. So, the graph is not 2-edge connected.
Naive Approach: The Naive approach is to check that on removing any edge X, if the remaining graph G – X is connected or not. If the graph remains connected on removing every edge one by one then it is a 2-edge connected graph. To implement the above idea, remove an edge and perform Depth First Search(DFS) or Breadth-First Search(BFS) from any vertex and check if all vertices are covered or not. Repeat this process for all E edges. If all vertices cannot be traversed for any edge, print No. Otherwise, print Yes.
Time Complexity: O(E * ( V + E))
Auxiliary Space: O(1)
Efficient Approach: The idea to solve this problem is:
Bridges in a graph: An edge in an undirected connected graph is a bridge if removing it disconnects the graph. For a disconnected undirected graph, definition is similar, a bridge is an edge removing which increases number of disconnected components.
=> If there is any bridge in the graph then it will never be a 2-edge connected otherwise it will be a 2-edge connected.
Below is the Implementation of the above approach:
Given graph is not 2-edge connected
Time Complexity: O(V + E)
Auxiliary Space: O(V)