Why it matters

SCC is fundamental for directed graph analysis. Kosaraju is one classic approach.

Advertisement

The architecture

DFS on original: record finish order.

DFS on reverse graph in reverse finish order.

Each tree = one SCC.

Kosaraju SCCDFS originalrecord finish orderReverse edgestranspose graphDFS reversein reverse finishTarjan's SCC does it in one pass; Kosaraju simpler to explain
Kosaraju.
Advertisement

How it works end to end

First DFS: post-order stack.

Reverse edges.

Second DFS: pop stack, each tree = SCC.

Alternative: Tarjan (one pass).