Sub topic 9
Low-Link Values and Component Roots
This chapter assumes you already know three things from earlier chapters. You should know how DFS assigns discovery times. You should be able to classify edges as tree, back, forward, or cross edges. You should know the definition of a strongly connected component (SCC). The goal here is the one idea that makes Tarjan's algorithm possible: a single number per vertex, the low-link value, that tells DFS when it has just finished an entire SCC.
Component Roots
Run DFS over a directed graph. In every SCC, one vertex is discovered before all the others. Call that vertex the root of the component.
The root has a useful property. When DFS discovers it, every other vertex of the SCC is still undiscovered and can be reached from the root. By the white-path theorem, every vertex of the SCC therefore becomes a descendant of the root in the DFS tree. So each SCC sits inside the DFS subtree of its root. That subtree may also contain other SCCs, each hanging below its own root.
So if DFS can recognize the root at the moment the root finishes, it can cut off the component right then. The vertices to cut off are the root's descendants that have not already been assigned to a deeper component. Low-link values give us that test.
Defining the Low-Link Value
Let index[v] be the discovery counter of v (0, 1, 2, ...). Tarjan's algorithm keeps a stack of vertices whose components are not yet finished. A vertex is pushed when it is discovered and popped only when its whole SCC is identified.
The low-link of v, written low[v], is the smallest index that DFS can reach from v by following zero or more tree edges down through v's subtree and then at most one non-tree edge to a vertex that is still on the stack.
It is computed incrementally while v is active:
| Edge `v -> w` seen during DFS | Update |
|---|---|
| `w` undiscovered (tree edge) | recurse into `w`, then `low[v] = min(low[v], low[w])` |
| `w` discovered and on the stack (back edge, or cross edge into an unfinished SCC) | `low[v] = min(low[v], index[w])` |
| `w` discovered and not on the stack (cross edge into a finished SCC) | ignore |
low[v] starts equal to index[v] and can only decrease, so low[v] <= index[v] always holds.
The Root Test
The central claim is:
v is the root of its SCC if and only if low[v] == index[v] once all of v's edges have been processed.
Here is the reasoning in both directions.
- If
low[v] < index[v], then some path fromvreaches an on-stack vertexuwith a smaller index. A vertex on the stack whose index is smaller thanv's is either an ancestor ofvor in an unfinished component whose root is an ancestor ofv. In both casesucan reachv, souandvare mutually reachable. Thenvshares an SCC with something discovered earlier, sovis not the root. - If
low[v] == index[v], then nothing inv's subtree escapes to an earlier unfinished vertex. Any earlier vertex in the same SCC asvwould need a path fromv's subtree back to it. That path would leave the subtree through an edge into an on-stack vertex with a smaller index, which would have loweredlow[v]. So no earlier vertex sharesv's component, andvis the root.
The next chapter turns this into a full proof. For now, the important part is why the on-stack restriction is there.
Why Finished Components Are Ignored
A vertex that is discovered but off the stack belongs to an SCC that was already completed. That SCC was popped because its root passed the root test, so no path leads from it back into anything still open. An edge v -> w into such a component means v reaches w, but w cannot reach v. Counting index[w] would make v look like part of an earlier component when it is not.
Worked Example
Use the graph from the diagram: adj = [[1], [2], [0, 3], [4], [5], [3], [5, 7], [6]]. DFS starts at 0.
- Discover 0, 1, 2 with indices 0, 1, 2. Edge
2 -> 0reaches an on-stack vertex, solow[2] = 0. - Edge
2 -> 3is a tree edge. Discover 3, 4, 5 with indices 3, 4, 5. Edge5 -> 3hits an on-stack vertex, solow[5] = 3. - Returning,
low[4] = min(4, 3) = 3andlow[3] = 3. Sincelow[3] == index[3], vertex 3 is a root. Pop 5, 4, 3 as one SCC. - Back at 2,
low[2] = min(0, low[3]) = 0. Thenlow[1] = 0andlow[0] = 0. Vertex 0 is a root. Pop 2, 1, 0. - Start a new tree at 6 with index 6. Edge
6 -> 5goes to a discovered vertex that is off the stack, so it is ignored. Discover 7 with index 7. Edge7 -> 6giveslow[7] = 6, solow[6] = 6, and 6 is a root. Pop 7, 6.
| Vertex | index | low | Root? |
|---|---|---|---|
| 0 | 0 | 0 | yes |
| 1 | 1 | 0 | no |
| 2 | 2 | 0 | no |
| 3 | 3 | 3 | yes |
| 4 | 4 | 3 | no |
| 5 | 5 | 3 | no |
| 6 | 6 | 6 | yes |
| 7 | 7 | 6 | no |
Seeing the On-Stack Check Matter
The code below computes index, low, and the roots in the order they finish. The check_on_stack flag lets you remove the on-stack restriction and watch the root test fail.
def low_links(n, adj, check_on_stack=True):
index = [None] * n
low = [0] * n
on_stack = [False] * n
stack = []
roots = []
counter = 0
def visit(v):
nonlocal counter
index[v] = low[v] = counter
counter += 1
stack.append(v)
on_stack[v] = True
for w in adj[v]:
if index[w] is None: # tree edge
visit(w)
low[v] = min(low[v], low[w])
elif on_stack[w] or not check_on_stack:
low[v] = min(low[v], index[w])
if low[v] == index[v]: # root test, after all edges
roots.append(v)
while True:
w = stack.pop()
on_stack[w] = False
if w == v:
break
for v in range(n):
if index[v] is None:
visit(v)
return index, low, roots
adj = [[1], [2], [0, 3], [4], [5], [3], [5, 7], [6]]
print(low_links(8, adj))
# ([0, 1, 2, 3, 4, 5, 6, 7], [0, 0, 0, 3, 3, 3, 6, 6], [3, 0, 6])
print(low_links(8, adj, check_on_stack=False))
# ([0, 1, 2, 3, 4, 5, 6, 7], [0, 0, 0, 3, 3, 3, 5, 6], [3, 0])Without the check, the cross edge 6 -> 5 drags low[6] down to 5. Vertex 6 fails the root test, so the component {6, 7} is never popped and never reported.
The Life of a Vertex
Each vertex goes through three states during Tarjan's algorithm. The low-link rule only cares about the middle one.
Low-Link Is a Witness, Not an Exact Minimum
low[v] is not guaranteed to equal the smallest index reachable from v among on-stack vertices. It takes at most one non-tree hop, and its value depends on the order in which edges are explored. The algorithm does not need an exact value. It only needs to know whether low[v] fell below index[v], and any single hop into an earlier open vertex is enough to show that. This is why the index[w] and low[w] variants give the same roots.
Exercise
For the graph with edges 0->1, 1->2, 2->0, 1->3, 3->4, 4->3 (adjacency lists in that order), run DFS from 0 and give index, low, and the roots in the order they are detected.
Show answer
index = [0, 1, 2, 3, 4], low = [0, 0, 0, 3, 3]. Vertex 3 is detected first (low[3] = index[3] = 3) and pops {4, 3}. Then vertex 0 is detected (low[0] = index[0] = 0) and pops {2, 1, 0}.
Exercise
An edge v -> w is a cross edge, and w is still on the stack. Why is it correct to use index[w] to lower low[v]?
Show answer
Since w is on the stack, its SCC is unfinished, so the root of w's SCC is still active, which makes it an ancestor of v. That root reaches v through tree edges, and w reaches its root. So v -> w closes a cycle through v, w, and that root, which puts v in an SCC with an earlier-discovered vertex. Lowering low[v] correctly marks v as a non-root.
Exercise
Suppose you move the check "if low[v] == index[v]" inside the edge loop, right after the first edge is processed. On the example graph, which vertex is wrongly declared a root, and why?
Show answer
Vertex 2. Its first edge 2 -> 0 lowers low[2] to 0, so 2 is safe. Vertex 3 is the problem. Its first edge is the tree edge 3 -> 4, and once that returns low[3] = 3, so the early test happens to give the right answer here. Vertex 6 is wrong: its first edge is 6 -> 5, which is ignored, so low[6] = 6 and 6 is declared a root before 6 -> 7 is explored. In this graph 7 still joins later, but in general vertices discovered after the early pop are left out of their true component. The test is only valid after all edges are processed.