AAI Agentic Handbook
Problem 48 · Graphs

Critical Connections (Tarjan Bridges)

HardClassic DSA & systems
01Problem

Given n servers and undirected connections, return all critical connections: edges whose removal disconnects some servers.

02Key insight

Tarjan's DFS tracks discovery time and low-link (earliest time reachable via a back edge). Edge (u,v) is a bridge iff low[v] > disc[u]. Use an iterative DFS for production-size graphs.

03Solution

Try it first.

TimeO(V+E)
SpaceO(V+E)
tests.py · 4 passing
tests.pypython4 lines
assert critical_connections(4, [[0,1],[1,2],[2,0],[1,3]]) == [[1,3]]
assert critical_connections(2, [[0,1]]) == [[0,1]]
assert sorted(map(sorted, critical_connections(5, [[0,1],[1,2],[3,4]]))) == [[0,1],[1,2],[3,4]]
assert critical_connections(3, [[0,1],[1,2],[2,0]]) == []
04Staff-level follow-up

Network topology for reliability planning: bridges are single points of failure; also compute articulation points (low[v] >= disc[u]) for single-node failures.