Sub topic 16
Bridges and Articulation Points with Low-Link Values
This chapter assumes you already know recursive DFS, discovery times, and how DFS labels tree edges and back edges. All graphs here are undirected, connected or not, and stored as adjacency lists.
What we are looking for
A bridge is an edge whose removal splits its connected component into two pieces. An articulation point (also called a cut vertex) is a vertex whose removal does the same. Both mark single points of failure, such as a network link or router that has no backup route around it.
The brute-force method deletes each edge or vertex in turn and reruns DFS, which costs O(E·(V + E)). A single DFS can find all of them in O(V + E).
The low-link value
During DFS, each vertex u gets a discovery time disc[u]. Its low-link low[u] is the smallest discovery time reachable from u by following tree edges down into its subtree and then at most one back edge.
The two tests read directly off these values. Here v is a tree child of u:
| Test | Meaning |
|---|---|
| `low[v] > disc[u]` | No back edge from `v`'s subtree reaches `u` or above, so edge `u–v` is a **bridge**. |
| `low[v] >= disc[u]`, `u` not the root | `v`'s subtree can reach `u` but nothing above it, so `u` is an **articulation point**. |
| `u` is the root with 2 or more tree children | The children's subtrees connect only through the root, so the root is an **articulation point**. |
The root needs its own rule because nothing sits above it. Every child of the root passes the >= test, even when the root has only one child and removing it disconnects nothing.
Implementation
def bridges_and_cut_vertices(graph):
disc, low = {}, {}
bridges, cut = [], set()
timer = [0]
def visit(u, parent):
disc[u] = low[u] = timer[0]
timer[0] += 1
children = 0
for v in graph[u]:
if v not in disc: # tree edge
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.add(u)
elif v != parent: # back edge
low[u] = min(low[u], disc[v])
if parent is None and children > 1:
cut.add(u)
for node in graph:
if node not in disc:
visit(node, None)
return bridges, cut
graph = {
"A": ["B", "C"], "B": ["A", "C"], "C": ["A", "B", "D"],
"D": ["C", "E"], "E": ["D"],
}
bridges, cut = bridges_and_cut_vertices(graph)
print(bridges) # [('D', 'E'), ('C', 'D')]
print(sorted(cut)) # ['C', 'D']Here is the trace. DFS discovers A, B, C, D, E at times 0 through 4. At C, the back edge to A sets low[C] = 0, and that value propagates up to B and A. D and E have no back edges, so low[D] = 3 and low[E] = 4. Both are greater than their parents' discovery times, so C–D and D–E are bridges.
Common errors
- Skipping the parent by vertex instead of by edge. The
v != parentcheck is wrong for multigraphs. If two parallel edges joinuandv, the pair cannot be a bridge, but this code skips both edges and reports one. To handle that case, skip only the edge ID you arrived by. - Using
low[v]on back edges. For a back edge, usedisc[v]. Usinglow[v]happens to work for bridges, but it can give wrong articulation points. - Forgetting the root rule, which marks every root as a cut vertex.
- Recursion depth. Python's default limit of about 1000 frames fails on long paths. Raise the limit with
sys.setrecursionlimitor convert the search to an explicit stack. - Reporting duplicates. One vertex can pass the
>=test for several children. Store cut vertices in a set.
Exercise
In a cycle graph of 5 vertices (each vertex joined to two neighbors in a ring), how many bridges and articulation points are there, and which low-link fact explains it?
Show answer
There are none of either. Every non-root vertex's subtree has a back edge to the root, so low[v] = 0 for every vertex. That makes low[v] > disc[u] fail for every tree edge, and low[v] >= disc[u] fail for every non-root u. The root has only one tree child, so the root rule does not apply either.
Exercise
Add the edge E–C to the example graph. Which bridges and articulation points remain?
Show answer
No bridges remain, and the only articulation point is C. The back edge from E to C gives low[E] = low[D] = 2 = disc[C]. That removes both bridges, since 2 is not greater than 2, and clears D, since low[E] = 2 < disc[D] = 3. C still qualifies because low[D] = 2 >= disc[C] = 2.