Sub topic 16
Bridges and Articulation Points with Low-Link Values
A network can stay connected even when most of its links are redundant. A few edges or vertices may still be single points of failure, and finding them is a common job for DFS. This chapter shows how one DFS pass, extended with a low-link value per vertex, finds every one of them in O(V + E) time.
This chapter assumes you already know recursive DFS, discovery times, and the difference between tree edges and back edges, all from earlier chapters. All graphs here are undirected and stored as adjacency-list dictionaries.
The Two Questions
A bridge is an edge whose removal increases the number of connected components. An articulation point (also called a cut vertex) is a vertex whose removal, together with its edges, increases the number of connected components.
The naive approach removes each edge or vertex in turn and runs a full traversal to check connectivity. That costs O(E · (V + E)) for bridges and O(V · (V + E)) for articulation points. Low-link values bring both down to one traversal.
Why DFS Structure Makes This Possible
In an undirected graph, DFS produces only tree edges and back edges. Cross edges cannot occur. If DFS is at u and sees an unvisited neighbor, it descends into that neighbor. So any edge between two different subtrees would have been used as a tree edge.
Every non-tree edge therefore connects a vertex to one of its own ancestors. That fact explains the whole algorithm. Take a tree edge u → v. The subtree rooted at v can reach the rest of the graph without that edge only if some back edge leaves the subtree and lands on u or an ancestor of u. If no such back edge exists, the subtree hangs from u by that single tree edge.
Defining Low-Link
Let disc[u] be the discovery time of u. The low-link value low[u] is the smallest discovery time reachable from u by following zero or more tree edges down into u's subtree and then at most one back edge.
You compute it during DFS as the minimum of:
disc[u]itself,disc[w]for every back edgeu — w,low[v]for every tree childv, taken aftervfinishes.
The last term pushes information upward. When visit(v) returns, low[v] already summarizes the highest point the whole subtree can reach.
The Two Tests
With disc and low in hand, both questions reduce to comparisons on each tree edge u → v:
| Structure | Condition | Meaning |
|---|---|---|
| Bridge `u — v` | `low[v] > disc[u]` | Nothing in `v`'s subtree reaches `u` or higher, so the subtree's only link upward is this edge. |
| Articulation point `u` (non-root) | `low[v] >= disc[u]` for some child `v` | `v`'s subtree can reach `u` but nothing above it, so removing `u` cuts the subtree off. |
| Articulation point `u` (DFS root) | `u` has two or more tree children | No edge links separate subtrees of the root, so removing the root splits them. |
The two vertex tests differ by one character: > for bridges and >= for articulation points. If a back edge from the subtree lands exactly on u, the edge u — v lies on a cycle and is not a bridge. Vertex u itself is still a cut point, because deleting u deletes that back edge too.
The root needs its own rule. It has no ancestors, so low[v] >= disc[root] holds for every child and tells you nothing.
Implementation
def find_bridges_and_cut_vertices(graph):
disc = {}
low = {}
bridges = []
cut_vertices = set()
timer = [0]
def visit(u, parent):
disc[u] = low[u] = timer[0]
timer[0] += 1
children = 0
skipped_parent = False
for v in graph[u]:
if v == parent and not skipped_parent:
# Skip the tree edge back to the parent exactly once.
skipped_parent = True
continue
if v in disc:
# Back edge to an ancestor: use its discovery time.
low[u] = min(low[u], disc[v])
else:
children += 1
visit(v, u)
low[u] = min(low[u], low[v])
if low[v] > disc[u]:
bridges.append((u, v))
if parent is not None and low[v] >= disc[u]:
cut_vertices.add(u)
if parent is None and children > 1:
cut_vertices.add(u)
for node in graph:
if node not in disc:
visit(node, None)
return bridges, cut_vertices
graph = {
"A": ["B", "C"],
"B": ["A", "C"],
"C": ["A", "B", "D"],
"D": ["C", "E", "F"],
"E": ["D", "F"],
"F": ["D", "E"],
}
bridges, cuts = find_bridges_and_cut_vertices(graph)
print(bridges) # [('C', 'D')]
print(sorted(cuts)) # ['C', 'D']The outer loop starts a fresh DFS in each connected component, so disconnected graphs work. Every vertex and every adjacency entry is processed once, so the running time stays O(V + E).
Tracing the Example
DFS starts at A and goes A → B → C → D → E → F. The table shows the final values.
| Vertex | `disc` | `low` | Why `low` has this value |
|---|---|---|---|
| A | 0 | 0 | Its own discovery time |
| B | 1 | 0 | Child C reaches A |
| C | 2 | 0 | Back edge C — A |
| D | 3 | 3 | Its subtree reaches D but nothing above |
| E | 4 | 3 | Child F reaches D |
| F | 5 | 3 | Back edge F — D |
Now check each tree edge:
- C → D:
low[D] = 3 > disc[C] = 2, so C — D is a bridge. Because3 >= 2and C is not the root, C is an articulation point. - D → E:
low[E] = 3is not greater thandisc[D] = 3, so D — E is not a bridge. Because3 >= 3, D is an articulation point. - B → C:
low[C] = 0 < disc[B] = 1, so neither test fires. - A is the root with one tree child, so it is not a cut vertex.
Common Errors and Gotchas
Using `low[w]` instead of `disc[w]` for back edges
Some versions write low[u] = min(low[u], low[w]) for a back edge. That still finds bridges correctly, but it can miss articulation points. Suppose a back edge lands on u, and u has its own back edge to a higher ancestor. Then low[u] is smaller than disc[u], the child appears to reach above u, and u is wrongly cleared. Use disc[w] for back edges.
Skipping every edge to the parent
A common shortcut ignores any neighbor equal to parent. With parallel edges, such as two cables between the same pair of routers, the second copy is a real back edge, and ignoring it marks the pair as a bridge when it is not. The code above skips the parent only once, which handles duplicate entries in the adjacency list. If edges carry IDs, the cleaner fix is to skip by edge ID instead of by vertex.
Forgetting the root rule
If you apply low[v] >= disc[u] to the root, every root with at least one child gets reported. The root needs the separate child-count test.
Recursion depth
Python's default recursion limit is about 1000. A long path graph will raise RecursionError. For large inputs, convert the DFS to an explicit stack of (vertex, neighbor_iterator) frames. The low update then happens when a frame is popped, which is the moment the child finishes.
Assorted edge cases
- An isolated vertex has no children and is never reported.
- A self-loop
u — usetslow[u]todisc[u], which has no effect. - Each endpoint of a bridge is an articulation point unless that endpoint has degree 1. A leaf hanging from a bridge is not a cut vertex.
Where This Leads
The same disc and low bookkeeping, with a stack of edges added, splits a graph into biconnected components: maximal pieces that have no articulation point inside them. You may notice that this resembles Tarjan's strongly connected components algorithm from the previous chapter. Both use low-link values. Tarjan's SCC algorithm works on directed graphs and tracks which vertices are still on a stack. The bridge algorithm needs no such stack, because undirected DFS has no cross edges to filter out.
Exercise
In the path graph 1 — 2 — 3 with DFS starting at 1, which edges are bridges and which vertices are articulation points? Give the disc and low values.
Show answer
disc = {1: 0, 2: 1, 3: 2} and low = {1: 0, 2: 1, 3: 2}, since there are no back edges. Both edges are bridges: low[2] = 1 > disc[1] = 0, and low[3] = 2 > disc[2] = 1. Vertex 2 is an articulation point because low[3] = 2 >= disc[2] = 1 and vertex 2 is not the root. Vertex 1 is the root with one child, so it is not a cut vertex. Vertex 3 has no children, so it is not a cut vertex either.
Exercise
Change the example graph by adding the edge B — E. What do the function's outputs become, and why?
Show answer
It returns no bridges and no articulation points. The new edge creates the cycle B — C — D — E — B, so C — D now lies on a cycle and is no longer a bridge. When D's subtree is explored, it can reach B through a back edge, so low[D] drops below disc[C] and both cut tests fail for C and D. The graph is now biconnected.
Exercise
A student writes if v == parent: continue and runs the function on {"x": ["y", "y"], "y": ["x", "x"]}, which has two parallel x–y edges. What goes wrong, and what does the chapter's version report?
Show answer
The shortcut skips both copies of the x–y edge. low[y] stays at disc[y], so x — y is wrongly reported as a bridge. The chapter's version skips the parent only once, so it treats the second copy as a back edge. That sets low[y] = disc[x], and the function returns no bridges and no articulation points.