On this page
A directed graph has one-way edges: course prerequisites, web links, functions calling each other. Which vertices can all reach one another, and how does a computer find those groups fast? We work both classic algorithms by hand on one graph so you can check each step.
What is a strongly connected component?
Two vertices u and v are strongly connected when there is a directed path from u to v and another from v to u. This is an equivalence relation, so it splits the vertices into blocks called strongly connected components, or SCCs (2-satisfiability, Wikipedia). A vertex on no cycle is an SCC on its own.
Our example has 8 vertices, a to h, and 11 edges:
a→b, b→c, c→a
b→d, d→e, e→d
c→f, f→g, g→f
e→g, g→h
Its SCCs are {a, b, c}, {d, e}, {f, g} and {h}, outlined in the diagram above.
How does Kosaraju's algorithm work?
Kosaraju's algorithm runs two depth-first searches (DFS). It is credited to S. Rao Kosaraju and to Micha Sharir, who published it in 1981 (Sharir 198190008-0); history on Wikipedia). It rests on one fact: reversing every edge leaves the SCCs unchanged.
Run DFS on the graph and note when each vertex finishes (all its descendants done).
Reverse every edge.
Take vertices in decreasing finish time. Each unvisited one starts a DFS in the reversed graph, and everything that search reaches is one SCC.
On our graph, visiting neighbours in the order listed:
Pass 1 from a goes a, b, c, f, g, h, then backs up to b and visits d and e. Finish order: h, g, f, c, e, d, b, a.
Pass 2 starts at a, the last to finish. In the reversed graph a reaches c, then b: the first SCC is {a, b, c}.
Next unvisited in that order is d. Its reversed edges lead to b (taken) and e: {d, e}.
Then f reaches g: {f, g}. Finally h, whose only reversed edge goes to g, already taken: {h}.
What is the condensation of a directed graph?
Shrink each SCC to one vertex and keep an edge between two components whenever some original edge joins them. This condensation is always a directed acyclic graph (DAG), because a cycle between components would merge them into one (2-satisfiability, Wikipedia). Ours has edges ABC→DE, ABC→FG, DE→FG and FG→H.
Kosaraju produced the components in this topological order. For ordering any DAG, see our guide to topological sort.
How does Tarjan's algorithm find SCCs in one pass?
Robert Tarjan's 1972 paper gave an SCC algorithm whose time and space are at most linear in the number of vertices plus edges (Tarjan, SIAM Journal on Computing). It needs one DFS and a stack.
Each vertex gets an index (the order it was discovered) and a low-link: the smallest index it can reach through its DFS subtree plus at most one edge to a vertex still on the stack. When a vertex finishes with low-link equal to its own index, it is the root of an SCC: pop the stack down to it.
On our graph, starting from a:
Indices: a 0, b 1, c 2, f 3, g 4, h 5, d 6, e 7.
h has no edges out, so low(h) = 5, its own index: pop {h}.
g has an edge back to f on the stack, so low(g) = 3. f finishes with low 3, its own index: pop {f, g}.
c's edge to a gives low(c) = 0, and b inherits 0.
e's edge to d gives low(e) = 6. d finishes with low 6: pop {d, e}. The edge e→g is ignored, because g has already left the stack.
a finishes with low 0: pop {a, b, c}.
Tarjan emits components in reverse topological order: {h} first, {a, b, c} last.
Where are strongly connected components used?
Cycles of dependencies. In a build system or study plan, any SCC with more than one vertex is a loop of tasks waiting on each other. Break those; the condensation orders the rest.
2-SAT. Write each clause (x or y) as two implications, not-x → y and not-y → x. Aspvall, Plass and Tarjan showed in 1979 that the formula is satisfiable exactly when no variable shares an SCC with its own negation, which gives a linear-time test (Information Processing Letters90002-4); summary on Wikipedia).
Compilers. Sharir's 1981 paper names data flow analysis in its title as the application.
For all-pairs reachability, Floyd–Warshall also finds which vertices reach each other, more slowly.
A practice plan
Draw your own 8-vertex directed graph with at least two cycles.
Run Kosaraju (write the finish order), then Tarjan (write each index and low-link).
Check both give the same partition, in reversed orders.
If low-link or finish time feels shaky, the Fermi Concept Library explains concepts across mathematics and computing, and the Fermi Problem Library has a step-by-step solver that explains the reasoning.



