VOOZH about

URL: https://www.geeksforgeeks.org/dsa/find-all-critical-connections-in-the-graph/

⇱ Find all Critical Connections in the Graph - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Find all Critical Connections in the Graph

Last Updated : 23 Jul, 2025

Given an undirected Connected graph of V vertices and E edges. A critical connection is an edge that, if removed, will make some nodes unable to reach some other nodes, the task is to find all critical connections in the graph.

Note: There are many possible orders for the answer. You are supposed to print the edges in sorted order, and also an edge should be in sorted order too. So if there's an edge between nodes 1 and 2, you should print it like (1,2) and not (2,1).

Examples:

Input:

👁 Image

Output: 0 1 0 2 Explanation: Both the edges in the graph are Crtical connections.

Input:

👁 Image

Output: 2 3 Explanation: The edge between nodes 2 and 3 is the only Critical connection in the given graph.

Approach: To solve the problem follow the below idea:

  • An edge is a critical connection, if and only if it is not in a cycle.
    • So, if we know how to find cycles, and discard all edges in the cycles, then the remaining connections are a complete collection of critical connections.

Follow the steps to solve the problem:

  • Use DFS algorithm to decide whether an edge is in a cycle or not.
  • Assign a rank or depth to each node while traversing using the dfs. As we keep moving into the depth in the dfs, if some how we jump to node which has lower depth and already visited this means a cycle is found and the edges present in this cycle is not critical connections.
  • But only the current level of search knows it finds a cycle. How does the upper level of search knows, if you backtrack?
    • Let's make use of the return value of DFS: dfs function returns the minimum rank it finds. During a step of search from node u to its neighbor vif dfs(v) returns something smaller than or equal to rank(u), then u knows its neighbor v helped it to find a cycle back to u or u's ancestor. So u knows it should discard the edge (u, v) which is in a cycle.

Below is the Implementation of the above approach:


Output
0 1
0 2

Time Complexity: O(V) + ElogE
Auxiliary Space : O(V)

Comment