Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

Algorithms · Graphs

The Weak Links.

Which single connection, if it failed, would split a network in two? That edge is a bridge; the analogous vertex is an articulation point. Tarjan finds them all in a single depth-first search using two numbers per node: disc[v], the order it was discovered, and low[v], the earliest-discovered node its subtree can reach by any path. An edge to a child c is a bridge exactly when low[c] > disc[v] — the child’s subtree has no other way back. Step the DFS and watch the two numbers fill and the critical edges light up.

O(V + E) — one DFS · disc[v] = discovery order · low[v] = earliest reachable
bridge

An edge whose removal increases the number of disconnected components.

articulation point

A vertex whose removal disconnects the graph.

disc[v]

The step number when the DFS first reached v — its discovery time.

low[v]

The smallest disc reachable from v’s subtree via tree or back edges.

bridges.js — disc, low, and the critical edges
Ready
Two triangles joined by a thin chain. A DFS assigns each node a discovery time disc and a low-link low. An edge to a child is a bridge when the child’s subtree can’t reach back above it. Step the DFS.
–
at node
0/7
visited
0
bridges

How it works

The magic number is low[v]: the earliest-discovered vertex reachable from v’s subtree using tree edges plus at most one “back edge” to an ancestor. A node starts with low[v] = disc[v], then lowers it whenever a back edge or a child’s subtree offers a way to an older ancestor. Now consider the tree edge from v down to a child c: if low[c] > disc[v], the entire subtree under c can reach nothing older than c itself — so that one edge is the only route in or out. Remove it and the subtree falls off: it’s a bridge. (Articulation points use the closely-related test low[c] ≥ disc[v], with a special rule for the DFS root.)

1

DFS and stamp discovery times

Run a depth-first search from any node. The moment you first reach a node, stamp it with the next discovery number and initialize its low-link to the same value.

2

Lower the low-link

When you find a back edge to an already-visited ancestor, or return from a child, update low[v] to the smallest disc your subtree can reach. This records the earliest ancestor still reachable.

3

Test each tree edge

For a tree edge v→c, if low[c] > disc[v], the child’s subtree has no alternative route above v, so v→c is a bridge. (For an articulation point, the test is low[c] ≥ disc[v].)

✓

One pass finds them all

A single DFS computes every disc and low value and identifies all bridges (and articulation points) in O(V + E) — no need to try removing edges one at a time.

Time
O(V + E)
Passes
one DFS
Bridge test
low[c] > disc[v]
Finds
weak links

The code

# Tarjan bridge-finding in one DFS, O(V + E) def dfs(v, parent_edge): disc[v] = low[v] = time[0]; time[0] += 1 for (u, eid) in adj[v]: if eid == parent_edge: continue if disc[u] == -1: # tree edge dfs(u, eid) low[v] = min(low[v], low[u]) if low[u] > disc[v]: bridges.append((v, u)) # v-u is a bridge else: # back edge low[v] = min(low[v], disc[u])

Quick check

1. What is a bridge in a graph?

2. What does low[v] represent?

3. When is the tree edge v→c a bridge?

FAQ

What are bridges and articulation points?

In an undirected graph, a bridge is an edge whose removal disconnects the graph, and an articulation point (cut vertex) is a vertex whose removal does. They identify the single points of failure — the links and hubs whose loss splits the network.

How does Tarjan’s algorithm find them in one DFS?

A DFS stamps each node with a discovery time disc[v] and a low-link low[v] (earliest node reachable from its subtree). A tree edge v→c is a bridge when low[c] > disc[v]; a non-root v is an articulation point when a child has low[c] ≥ disc[v]; the root is one if it has 2+ DFS children. All in O(V + E).

Why is low[v] compared with disc, not low, in the bridge test?

A back edge lowers low[v] using the ancestor’s disc (the node you actually reach), not its low. The test low[c] > disc[v] then asks whether c’s subtree can reach v or anything older; if it can’t, the connecting edge is the sole crossing — a bridge.

What are bridges and articulation points used for?

Network reliability and single-point-of-failure analysis (communication, power, transport), finding critical roads/links, decomposing graphs into biconnected components, and as a subroutine in other graph algorithms — answering “what weakest link, if lost, breaks connectivity?”

The picture: disc and low on the page’s graph

00/011/022/033/344/455/466/4bridgebridgelabel = disc/low · shaded = articulation point · accent line = bridgelow[4] = 4 > disc[3] = 3, and low[3] = 3 > disc[2] = 2
The page’s seven-vertex graph, each vertex labelled disc/low. Inside the left triangle every low-link falls to 0, because a back edge reaches the root. In the right triangle everything bottoms out at 4. Only vertices 3 and 4 keep their own numbers as low, and the two edges that join those regions are the bridges.

Worked example, step by step

Run the algorithm on the edges 0-1, 1-2, 2-0, 2-3, 3-4, 4-5, 5-6, 6-4, visiting neighbours in the order the edges were listed and starting at vertex 0. Each step is one thing the DFS does.

StepEventUpdateBridge test low[child] > disc[parent]
1visit 0, 1, 2 down the treedisc = 0, 1, 2; low = 0, 1, 2—
2at 2, edge to 0 is a back edgelow[2] = min(2, disc[0]) = 0—
3visit 3, 4, 5, 6disc = 3, 4, 5, 6—
4at 6, edge to 4 is a back edgelow[6] = min(6, disc[4]) = 4—
5return 6 → 5low[5] = 44 > disc[5] = 5? no
6return 5 → 4low[4] = 4low[5] = 4 > disc[4] = 4? no
7at 4, edge to 6 already seendisc[6] = 6 does not lower low[4]—
8return 4 → 3low[3] = 3low[4] = 4 > disc[3] = 3? yes: bridge 3–4
9return 3 → 2low[2] = 0low[3] = 3 > disc[2] = 2? yes: bridge 2–3
10return 2 → 1, then 1 → 0low[1] = 0, low[0] = 00 > 1? no; 0 > 0? no

Two things stand out. First, the test is never made at a back edge: it happens only when the DFS returns up a tree edge, which is why the order of the steps matters. Second, vertices 3 and 4 pass the test as children (low 3 > 2, low 4 > 3) while 5 fails it: the triangle at the far end loops back to 4 itself, so low[5] = 4 is not greater than disc[4] = 4. The comparison is strict for bridges. The same run also gives the articulation points 2, 3, 4: with ≥ in place of >, vertices 2, 3 and 4 each have a child that cannot get above them, so removing any of them splits the graph.

Complexity and trade-offs

CaseTimeSpaceWhy
Tarjan, one DFSO(V + E)O(V)Every vertex and edge is touched once, and the arrays disc, low and the recursion stack are O(V).
Remove each edge, re-check connectivityO(E · (V + E))O(V)Simple and obviously correct, so it is a good test oracle, but quadratic on sparse graphs.
Chain decompositionO(V + E)O(V + E)Same bound with a different method: edges not on any cycle are the bridges.
Remove each vertex, re-check connectivityO(V · (V + E))O(V)The brute-force check for articulation points; useful as a test oracle.

The linear bound is optimal because every edge has to be read once. The practical limit is stack depth, not time: the recursive form needs a stack as deep as the longest DFS path, and a graph shaped like a long path is the worst case. Large inputs usually call for an explicit stack.

Common mistakes

  • Not skipping the edge you came from

    Treating the tree edge back to the parent as a back edge makes every low-link reach its parent, so no child can ever beat its parent. On this page’s graph the buggy version returns [] instead of [[3,4],[2,3]], and low becomes [0,0,0,2,3,4,4].

  • Skipping the parent by vertex, not by edge id

    With two parallel edges between 0 and 1, there is a second route, so neither is a bridge. Skipping “any edge back to the parent vertex” discards both, and the buggy version reports [[0,1]] as a bridge; skipping only the edge id used to arrive correctly reports none.

  • Using ≥ for the bridge test

    The articulation-point test is low[child] ≥ disc[parent], and the bridge test is strict. On this page’s graph the non-strict version reports 4 bridges (0–1, 2–3, 3–4, 4–5); only 2–3 and 3–4 are real. Edges inside a cycle can never be bridges.

  • Applying the child-count rule to non-roots

    The root is an articulation point only if it has at least two DFS children. Applying the ≥ test to the root instead flags it every time: on the plain triangle 0-1-2 the buggy code reports vertex 0 as a cut vertex although removing it leaves 1-2 connected. For non-root vertices the ≥ test is the right one.

  • Recursing on a long path

    A path of 100,000 vertices is a legal input, and a recursive DFS on it threw a RangeError (stack overflow) in a test run. Use an explicit stack when the graph can be deep, or raise the limit and hope.

Where this shows up

  • Network reliability

    A bridge is a link whose failure partitions the network, and an articulation point is a router or switch that does the same. Finding them is the first step in deciding where to add redundancy.

  • Biconnected components

    Cutting the graph at its articulation points gives the biconnected components, the pieces that survive any single vertex failure. The same low-link bookkeeping, with a stack of edges, produces them.

  • Interview and contest problems

    “Critical connections in a network” is the standard bridge-finding question, and many graph problems first contract the 2-edge-connected components into a tree of bridges.

  • Road and dependency maps

    The same test finds the only road into a district or the only module that connects two parts of a build graph.

SOLVE IT YOURSELF

Solve it: find the edges that would split the network

A bridge is an edge with no alternative route around it — cut it and the graph falls into two pieces. One DFS finds every one of them. Python or TypeScript, running for real in your browser.

YOUR TASK

Implement find_bridges(n, edges) for an undirected graph: return every bridge as a sorted (u, v) pair, in sorted order. Parallel edges between the same two vertices mean neither is a bridge.

HINTS — 5 IDEAS
  1. Give each node a disc (discovery time) and a low (the earliest discovery time reachable from its subtree, including via one back edge).
  2. After recursing into child v: if low[v] > disc[u], then nothing in v’s subtree can reach u or above except through this edge — so it is a bridge.
  3. Strictly greater is the whole test. >= would wrongly flag edges inside a cycle.
  4. Skip the edge you arrived on — but skip it by edge index, not by vertex. Skipping "any edge back to my parent" silently mishandles parallel edges, which are exactly the case where an edge is not a bridge.
  5. For a back edge to an already-visited node, use disc[v], not low[v].
CPython · WebAssembly

Keep going

Finished this one? 0 / 99 Algorithms done
NextSix Degrees: Union-Find Closest algorithm to this one

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Algorithms