Problem Description
Given an undirected network of n servers (numbered from 0 to n - 1) and a list of connections (each connection is a pair of servers), find all critical connections in the network. A critical connection (or bridge) is an edge that, if removed, will disconnect some part of the network, meaning some servers will no longer be able to communicate with others.
Key Insights
- The problem is about identifying bridges in an undirected graph.
- Use Depth-First Search (DFS) to explore the graph.
- During DFS, track discovery times and low-link values for each node.
- For an edge (u, v), if low[v] > disc[u] then (u, v) is a critical connection.
- Tarjan's algorithm is well-suited for solving this problem in O(n + m) time.
Space and Time Complexity
Time Complexity: O(n + m) where n is the number of nodes and m is the number of connections. Space Complexity: O(n + m) for the graph representation and DFS recursion stack.
Solution
We solve this problem using a DFS-based approach (Tarjan's algorithm). First, we transform the list of connections into an adjacency list for efficient graph traversal. We then start a DFS from an arbitrary node (node 0, since the graph is connected) while maintaining two arrays: one for discovery times (disc) and one for low-link values (low). The discovery time is the time when the node is first visited, and the low-link value is the smallest discovery time that can be reached from that node (including via back edges). For each edge (u, v), after a DFS call on v, if low[v] > disc[u] then the edge (u, v) is a bridge because v (and its descendants) cannot reach u or any of its ancestors without this edge. This edge is then recorded as a critical connection.