In a directed graph some groups of vertices can all reach each other: in a one-way street network, a district where you can drive from any junction to any other. These groups are the strongly connected components. They can be found with two depth-first searches.
Definition
“Maximal” means no vertex can be added without breaking the property. Every vertex belongs to exactly one SCC (a vertex on no cycle forms an SCC by itself). If each SCC is shrunk to a single vertex, the resulting graph is always a DAG.
The transpose GT=(V,ET) has the same vertices and every edge reversed: ET={(u,v):(v,u)∈E}. Its adjacency matrix is the transpose of G‘s. G and GT have exactly the same SCCs, because reversing every edge keeps “u and v reach each other” true.
The algorithm (Kosaraju)
Run DFS on G and record the finishing time f[u] of every vertex.
Compute GT.
Run DFS on GT, taking the start vertices in the main loop in decreasing order of f[u].
Each tree of the DFS forest from step 3 is one strongly connected component.
Two DFS runs and one transpose: O(n+e) with adjacency lists.
Uses
Simplifying a digraph into its “component DAG” before other algorithms.
Finding groups of web pages or accounts that all link to each other.
Detecting circular dependencies (each SCC with more than one vertex is a cycle of mutual dependencies).
Solving 2-SAT problems in logic.
Key takeaways
SCC: maximal set of vertices that can all reach each other.
GT reverses every edge and has the same SCCs as G.
Kosaraju: DFS on G (finishing times), then DFS on GT in decreasing finishing order; each tree is an SCC.
Runs in O(n+e); shrinking SCCs to single vertices gives a DAG.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Write the algorithm for finding the strongly connected components of a digraph and state its complexity.
Show worked answer
Strongly-Connected-Components(G): (1) call DFS(G) to compute the finishing time f[u] of every vertex; (2) compute the transpose GT by reversing every edge; (3) call DFS(GT), but in its main loop consider the vertices in order of decreasing f[u]; (4) output the vertices of each tree in the depth-first forest of step 3 as a separate strongly connected component. With adjacency lists, each DFS and the transpose take O(n+e), so the whole algorithm is O(n+e).
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-208/graphs/strongly-connected-components/ to read this page.