Core idea
Kosaraju's algorithm uses two DFS passes.
First pass finds the finishing times of nodes in the original graph.
Second pass runs DFS on the transposed (reversed) graph in order of decreasing finishing time.
How it works
- Run DFS on the original graph and push finished nodes to a stack.
- Reverse the direction of all edges to create a transposed graph.
- Pop nodes from the stack and run DFS on unvisited nodes in the transposed graph.
- Each resulting DFS forest is a Strongly Connected Component.