Graph Theory37 sections · 1633 units
Open in Course

Critical Connections - Algorithm

(Tarjan's bridge detection)

1.1. Build an adjacency list from the connections.

2.2. Initialize disc[v] = -1 for all vv (unvisited marker), low[v] = 0, timer=0timer = 0, result=[]result = [].

3.3. For each unvisited vertex, run DFS:

  • Set disc[v] = low[v] = timer, timer++timer{+}{+}
  • For each neighbor ww: if unvisited, recurse and update low[v]; if visited (not parent), update low[v] with disc[w]
  • If low[w] > disc[v], add (v,w)(v, w) to result

4.4. Return result.

This runs in O(V+E)O(V + E) time and uses O(V)O(V) space.