๐ WAYPOINT LESSON
Kosaraju's Two Passes
โญโญโญ advancedโณ 35 min read๐ Lesson 149 of 281
One DFS on G records finish order; one DFS on the reverse graph in reverse finish order labels every SCC โ proven by the finish-time ordering.
Two passes, one theorem
Pass 1: DFS over G, push each node when its DFS finishes. Pass 2: DFS over the REVERSE graph G^T, starting from unvisited nodes in decreasing finish order; each pass-2 tree is exactly one SCC.
Why it is correct: the node u with the largest finish time lies in a "source" SCC C of the condensation. Reversing the graph makes C a sink โ no edges leave C in G^T, so its pass-2 DFS cannot escape. Induction on the condensation finishes the proof.
Implementation must be ITERATIVE on both passes; build G^T once.