Strong Components in Linear Time
Explore the different techniques used to implement strong components in linear time efficiently.
Lemma for computing strong components
In fact, there are several algorithms to compute strong components in time, all of which rely on the following observation.
Lemma 1: Fix a depth-first traversal of any directed graph . Each strong component of contains exactly one node that does not have a parent in . (Either this node has a parent in another strong component, or it has no parent.)
Proof: Let be an arbitrary strong component of . Consider any path from one vertex to another vertex . Every vertex on this path can reach , and thus can reach every vertex in ; symmetrically, every node on this path can be reached by , and thus can be reached by every vertex in . We conclude that every vertex on this path is also in .
Let be the vertex in with the earliest starting time. If has a parent, then starts before and thus cannot be in .
Now let be another vertex in . Just before is called, every vertex in is new, so there is a path of new vertices from to . Lemma 1 now implies that is a descendant of in the depth-first forest. Every vertex on the path of tree edges to lies in ; in particular, .
Conclusion of lemma
The previous lemma implies that each strong component of a directed graph defines a connected subtree of any depth-first forest of In particular, for any strong component , the vertex in with the earliest starting time is the lowest common ancestor of all vertices in we call this vertex the root of .
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy