Tutorialspoint
Problem
Solution
Submissions

Critical Connections in a Network

Certification: Intermediate Level Accuracy: 0% Submissions: 1 Points: 10

You are given an undirected connected graph with n nodes labeled from 0 to n-1 and a list of edges where edges[i] = [u, v] represents an undirected edge between nodes u and v. Return all critical connections in the network in any order.

Example 1
  • Input: n = 4, connections = [[0,1],[1,2],[2,0],[1,3]]
  • Output: [[1,3]]
  • Explanation:
    • Step 1: Analyze the given graph with 4 nodes and 4 edges.
    • Step 2: Identify that nodes 0, 1, and 2 form a cycle.
    • Step 3: Edge [1,3] is the only critical connection because if removed, node 3 will be isolated.
    • Step 4: Return [[1,3]] as the result.
Example 2
  • Input: n = 6, connections = [[0,1],[1,2],[2,0],[1,3],[3,4],[4,5],[5,3]]
  • Output: []
  • Explanation:
    • Step 1: Analyze the given graph with 6 nodes and 7 edges.
    • Step 2: Identify that nodes 0, 1, and 2 form one cycle.
    • Step 3: Nodes 3, 4, and 5 form another cycle.
    • Step 4: Every edge in the graph is part of a cycle, so removing any single edge will not disconnect the graph.
    • Step 5: Return an empty list as there are no critical connections.
Constraints
  • 1 ≤ n ≤ 10^5
  • n-1 ≤ connections.length ≤ 10^5
  • 0 ≤ connections[i][0], connections[i][1] ≤ n-1
  • connections[i][0] != connections[i][1]
  • There are no repeated connections.
  • Time Complexity: O(V+E) where V is the number of vertices and E is the number of edges
  • Space Complexity: O(V+E)
GraphAlgorithmsIBMLTIMindtree
Editorial

Login to view the detailed solution and explanation for this problem.

My Submissions
All Solutions
Lang Status Date Code
You do not have any submissions for this problem.
User Lang Status Date Code
No submissions found.

Please Login to continue
Solve Problems

 
 
 
Output Window

Don't have an account? Register

Solution Hints

  • Use Tarjan's algorithm to find bridges in the graph.
  • Keep track of discovery time and low time for each node.
  • A bridge exists if the low value of the adjacent node is greater than the discovery time of the current node.
  • Build an adjacency list representation of the graph for efficient traversal.
  • Use depth-first search (DFS) to identify critical connections.

Steps to solve by this approach:

 Step 1: Build an adjacency list representation of the graph.

 Step 2: Initialize arrays to track discovery time, lowest reachable time, and visited status.
 Step 3: Implement a DFS function that updates these values as we traverse the graph.
 Step 4: For each node, check if any of its edges is a bridge by comparing discovery and low times.
 Step 5: A bridge exists if the low value of the adjacent node is strictly greater than the discovery time of the current node.
 Step 6: Collect all bridges found during the traversal.
 Step 7: Return the list of bridges (critical connections).

Submitted Code :