Articulation points
Find the nodes whose removal splits the graph, with one DFS and each node's low value (the earliest discovery time reachable from its subtree).
An articulation point (cut vertex) is a node whose removal disconnects the graph. Trying to remove each node in
turn costs O(V·(V + E)); one DFS is enough:
- Time:
O(V + E) - Space:
O(V) - Horowitz–Sahni, chapter 6
- Grimaldi, chapter 12
Two triangles joined by the bridge D — E; D and E are articulation points.
def articulation_points(graph, src):disc = {v: 0 for v in graph}low = {v: 0 for v in graph}cut = set()timer = [0]for s in graph:if disc[s] == 0:visit(graph, s, None, disc, low, cut, timer)return cutdef visit(graph, u, parent, disc, low, cut, timer):timer[0] = timer[0] + 1disc[u] = timer[0]low[u] = timer[0]children = 0for v, _ in graph[u]:if disc[v] == 0:children = children + 1visit(graph, v, u, disc, low, cut, timer)low[u] = min(low[u], low[v])if parent is not None:if low[v] >= disc[u]:cut.add(u)elif v != parent:low[u] = min(low[u], disc[v])if parent is None:if children > 1:cut.add(u)
Start
- Current node
(u) - Search tree (from parent)
- Edge being checked
Recursion tree
Filled orange = running call · Orange outline = still on the stack · Grey = finished
Local variables
src'A'
Orange = changed in this step
graph dict
- 'A': [('B', 1), ('D', 1)]
- 'B': [('A', 1), ('D', 1)]
- 'C': [('D', 1)]
- 'D': [('B', 1), ('A', 1), ('E', 1), ('C', 1)]
- 'E': [('D', 1), ('F', 1), ('G', 1)]
- 'F': [('E', 1), ('G', 1)]
- 'G': [('F', 1), ('E', 1)]
Call stack
- articulation_points()line 1
Step 1 of 150
How the work grows with input size
Average of 5 random graphs per n (fixed seeds). Hollow marker = the input on screen.
- check
- current input (n=7)
Show as a table
| n | check |
|---|---|
| 4 | 10.4 |
| 8 | 27.6 |
| 12 | 41.6 |
| 16 | 56 |
| 20 | 70.8 |
| 24 | 74.4 |
| 28 | 94.4 |
Explanation
The idea
An articulation point (cut vertex) is a node whose removal disconnects the graph. Trying to remove each node in
turn costs O(V·(V + E)); one DFS is enough:
disc[u]: the timeuwas discovered.low[u]: the earliest discovery time reachable fromu's subtree (through tree edges and at most one back edge).
The rule
- A non-root node
uis an articulation point if it has a childvwithlow[v] ≥ disc[u]: the subtree ofvcannot reach aboveuwithout going throughu. - The root is an articulation point if it has more than one child in the DFS tree.
Cost
One DFS: O(V + E).
What to watch in the trace
- The number next to each node is its
low; watch back edges pull it down. - The
cutset in the memory panel holds the articulation points found so far.