Sub topic 9
Low-Link Values and Component Roots
This chapter assumes you already know recursive depth-first search (DFS), DFS discovery times, and the four edge types: tree, back, forward, and cross. It introduces the one number Tarjan's algorithm adds to each vertex. The full algorithm comes in the next chapter.
The problem low-link solves
Kosaraju's algorithm needs a second pass over the transpose to separate components. Tarjan's algorithm separates them during a single DFS. To do that, it must recognise the moment DFS finishes the first-discovered vertex of a component. That vertex is the component's root. Every other vertex in the component sits below the root in the DFS tree.
Discovery index and low-link
Each vertex v gets two numbers:
index[v]is a counter value assigned when DFS first visitsv. It works like a discovery time.low[v]is the smallest index thatvcan reach by going down the DFS subtree ofvand then following at most one edge to a vertex that is still on the stack.
The stack holds visited vertices whose component has not yet been completed. When a vertex is pushed, it stays on the stack until its whole component is popped together.
Low-link is updated in two cases while v scans its edge v → w:
| Situation for `w` | Edge type | Update |
|---|---|---|
| Not yet visited | Tree edge | Recurse, then `low[v] = min(low[v], low[w])` |
| Visited and on the stack | Back edge, or cross edge inside an unfinished component | `low[v] = min(low[v], index[w])` |
| Visited and off the stack | Edge into a completed component | Ignore |
The root test
When DFS finishes v, check whether low[v] == index[v].
If the test holds, nothing in v's subtree can reach a vertex discovered before v that is still unassigned. That makes v a root, and v together with everything above it on the stack forms one strongly connected component. If low[v] < index[v], then v can get back to an earlier vertex that is still on the stack, so v belongs to that earlier vertex's component.
Worked trace
Use the graph adj = [[1], [2], [0, 3], [4], [5], [3], [5, 7], [6]] and start DFS at vertex 0.
- Vertices 0, 1, and 2 get indices 0, 1, and 2. Vertex 0 is on the stack, so edge
2 → 0setslow[2] = 0. - Vertices 3, 4, and 5 get indices 3, 4, and 5. Edge
5 → 3setslow[5] = 3. That value propagates up the tree, solow[4] = 3andlow[3] = 3. - Vertex 3 finishes with
low == index. The stack pops {5, 4, 3}. - Back at vertex 2,
low[2] = min(0, low[3]) = 0. The value 0 propagates to vertex 1 and then to vertex 0. Vertex 0 passes the root test, and the stack pops {2, 1, 0}. - A new DFS starts at vertex 6. Vertex 5 is already off the stack, so edge
6 → 5is ignored. Edge7 → 6setslow[7] = 6. Vertex 6 passes the root test, and the stack pops {7, 6}.
Exercise
In the trace, what would happen if vertex 7 had no edge back to 6?
Show answer
Vertex 7 would finish with low[7] = index[7] = 7, so it would be popped as its own component {7}. Vertex 6 would then finish with low[6] = 6, because the edge 6 → 5 is ignored, and it would be popped as {6}.
Exercise
Why can a vertex v with low[v] < index[v] never be the root of its component?
Show answer
Some vertex discovered before v is still on the stack and reachable from v's subtree. That vertex can also reach v, so the two share a component, and the earlier-discovered vertex is the root.