Search⌘ K
AI Features

Strong Components in Linear Time Continued

Explore how Tarjan's algorithm employs depth-first search and an auxiliary stack to compute strongly connected components in a directed graph efficiently. Learn to identify root vertices and sink components and understand the algorithm’s linear-time complexity. This lesson helps you implement and optimize strong component detection using Java.

Tarjan’s algorithm

An earlier but considerably more subtle linear-time algorithm to compute strong components was published by Bob Tarjan in 1972. Intuitively, Tarjan’s algorithm identifies a source component of GG, deletes it, and then recursively finds the remaining strong components; however, the entire computation happens during a single depth-first search.

Characterizing sink components in a directed graph

Fix an arbitrary depth-first traversal of some directed graph GG. For each vertex vv, let low(v)low(v) denote the smallest starting time among all vertices reachable from vv by a path of tree edges followed by, at most, one non-tree edge. Trivially, low(v)v.prelow(v) ≤ v.pre, because vv can reach itself through zero tree edges followed by zero non-tree edges. Tarjan observed that sink components could be characterized in terms of this low function.

Lemma: A vertex vv is the root of a sink component of GG if and only if low(v)=v.prelow(v) = v.pre and low(w)<w.prelow(w) < w.pre for every proper descendant ww of vv.

Proof: First, let vv be a vertex such that low(v)=v.prelow(v) = v.pre. Then there is no edge wxw\rightarrow x where ww is a descendant of vv and x.pre<v.prex.pre < v.pre. On the other hand, vv cannot reach any vertex yy such that y.pre>v.posty.pre > v.post. It follows that vv can reach only its descendants, and therefore any descendant of vv can reach only descendants of vv. In particular, vv ...