Bridges in Graph

hard

Given an undirected graph with V vertices (0 .. V-1) and edges edges (no self-loops or duplicate edges), return all bridges — edges whose removal increases the number of connected components. Return each bridge as [min(u,v), max(u,v)], and return the list sorted.

Hints

A bridge is an edge that lies on no cycle — removing it disconnects part of the graph.
DFS tracking disc[u] (discovery time) and low[u] (earliest reachable ancestor).
A tree edge u-v is a bridge iff low[v] > disc[u].

Common doubts

v's subtree has no back edge reaching u or above, so the edge (u,v) is the only connection holding that subtree on — a bridge.
A back edge climbs to an already-visited ancestor w; its discovery time is the level you can reach, so use disc[w].
With multi-edges, a second parallel edge to the parent forms a cycle and must be counted; skipping just one preserves that.

Interview follow-ups

Use low[v] ≥ disc[u] (non-strict) for non-root vertices, and handle the root by child count.
A graph is 2-edge-connected iff it has no bridges.

Fun facts

  • Bridges are exactly the edges not contained in any cycle — the 'cut edges' of the graph.
  • Tarjan's 1974 bridge algorithm shares its low-link engine with SCCs and articulation points.

Asked at

GoogleAmazonMicrosoft
Frequently Sometimes Occasionally
Example 1
Input: V = 4, edges = [[0,1],[1,2],[2,0],[2,3]]
Output: [[2,3]]
The triangle 0-1-2 has no bridge; 2-3 is the only link to vertex 3.
Example 2
Input: V = 4, edges = [[0,1],[1,2],[2,3],[3,0]]
Output: []
A single cycle has no bridges.
Constraints

- 1 <= V <= 10^5 - 0 <= edges.length <= 10^5 - no self-loops or duplicate edges

Solve this problem →