Use a global clock starting at zero, incrementing once on discovery and once on finish. Scan starting vertices and each adjacency list in increasing numerical order. The first search descends through , returns from , and then visits from . After that search finishes, the unvisited vertex starts a second tree.A dash denotes a root with no predecessor. is a forward edge: vertex is a proper descendant of , but its predecessor is . Its interval satisfies . is a back edge, because is still an active ancestor when it is examined. The other non-tree edge is also a back edge, while reaches an already finished vertex in a different search tree.[ref]
Depth-first search by Jeff Erickson. §6.1, discovery/finish intervals and edge classification
Use the two-pass strongly connected component algorithm: first run depth-first search on the original directed graph, then search its graph transpose in decreasing order of the first pass's finishing times. The first-pass order from part (a) isReversing the edges gives outgoing adjacency listsThe second pass first visits only . Its next new root is , whose search visits ; later entries already marked by this search are skipped. The next new root is , whose graph transpose neighbours have already been assigned. Therefore the components areWithin the middle component the directed cycle demonstrates mutual reachability. The source edge structure does not provide return paths from or to . More generally, decreasing finish order chooses a remaining component whose graph transpose search cannot escape to another still-unassigned component, so each second-pass tree is exactly one component. This explains the partition rather than merely listing it. The algorithm takes with adjacency lists.[ref]
Depth-first search by Jeff Erickson. §§6.5–6.6, strong components, condensation and the two-search construction