Discord

INAIO Guide Stage 1 12Graph Theory and Algorithms

12.5 Strongly connected components

Find mutually reachable groups, compress them into a simpler graph, and identify terminal components.

In Module 12.2, a directed route from AA to BB did not guarantee a route back. Now ask a stronger question: which vertices can reach one another in both directions? If AA can reach BB and BB can reach AA, they can communicate through the network even if they have no direct two-way edge. If BB and CC can also reach one another, joining those routes shows that AA and CC can reach one another too. This lets us group vertices by mutual reachability.

A strongly connected component (SCC) is one of these groups, extended as far as possible: every vertex in it can reach every other, and no additional vertex can join while that remains true. We use SCCs to compress a complicated network of cycles into a simpler map of one-way movement between groups. In a task-dependency graph, a component containing a cycle exposes a circular dependency. The compressed map also reveals sink components, which have no outgoing edge to another group. A process following edges can enter such a component but cannot leave it; that matters for state transitions and the random walks in Module 12.6.

This is intermediate graph theory. Review reachability and DFS first. The Johns Hopkins SCC lecture notes give a full algorithmic treatment.

A basic idea: mutual reachability makes a group

Suppose A→BA\to B, B→AB\to A, B→CB\to C, C→DC\to D, D→CD\to C, and D→ED\to E. First check return routes: AA and BB reach each other, and CC and DD reach each other. The arrow B→CB\to C lets the first pair reach the second, but there is no route from CC back to BB, so the pairs cannot be one SCC. Vertex EE has no way back to the others and forms a component by itself. The three groups are {A,B}\{A,B\}, {C,D}\{C,D\}, and {E}\{E\}.

Directed graph with strongly connected groups {A,B}, {C,D}, and {E}. A second panel compresses them into a chain {A,B} to {C,D} to {E}; {E} is marked as a sink component.Directed graph with strongly connected groups {A,B}, {C,D}, and {E}. A second panel compresses them into a chain {A,B} to {C,D} to {E}; {E} is marked as a sink component.
Compress mutual-reachability groups; the resulting arrows show which components can lead to others.

A quick tour of components and sinks

Maximal means that we cannot add another vertex to the group while keeping mutual reachability; it does not mean that the component has more vertices than every other component. Each vertex belongs to exactly one SCC. A single vertex is an SCC even without a self-loop, because a zero-length path reaches itself. An edge inside an SCC is allowed; a sink SCC only forbids edges leaving for a different SCC.

Compress every SCC into one node, keeping arrows between different components. This condensation graph has no directed cycle: if a cycle joined several components, each could reach the others and they would actually be one SCC. Therefore the condensation graph is a directed acyclic graph. A finite nonempty condensation graph has at least one sink.

For a small graph, trace reachability in both directions, group mutually reachable vertices, then scan outgoing edges from each group. For a large graph, Kosaraju's algorithm uses two DFS passes:

  1. DFS the original graph and record vertices when their searches finish.
  2. Reverse every edge.
  3. DFS the reversed graph in decreasing order of first-pass finishing time. Each new search marks one SCC.

The finishing order and reversal prevent a second-pass search from mixing components linked only one way. With adjacency lists, the two passes take O(∣V∣+∣E∣)O(|V|+|E|) time. The small-graph grouping method is enough to answer most hand questions; the two-pass algorithm makes the same task efficient on large graphs.

Pages have links A↔BA\leftrightarrow B, B→CB\to C, C↔DC\leftrightarrow D, and D→ED\to E. Find the SCCs and sink SCCs.

  1. Find mutual groups. A,BA,B reach each other; C,DC,D reach each other; EE stands alone. The SCCs are {A,B}\{A,B\}, {C,D}\{C,D\}, {E}\{E\}.
  2. Compress. The component arrows are {A,B}→{C,D}→{E}\{A,B\}\to\{C,D\}\to\{E\}.
  3. Identify sinks. Only {E}\{E\} has no arrow to another component, so it is the sole sink SCC.

Application 2: two possible terminal groups

A process has states S,A,B,CS,A,B,C and moves S→AS\to A, S→BS\to B, A→AA\to A, B→CB\to C, and C→BC\to B. Which components can trap a path once entered?

  1. Group mutual reachability. The SCCs are {S}\{S\}, {A}\{A\}, and {B,C}\{B,C\}.
  2. Check outgoing edges. {S}\{S\} points to both other groups. Neither {A}\{A\} nor {B,C}\{B,C\} points out.
  3. Conclude. Both {A}\{A\} and {B,C}\{B,C\} are sink SCCs. A path entering either cannot reach the other under these moves.

The two sinks explain why a process without added moves may have different long-run outcomes depending on its route.

Resources

SourceTitleWhy read it
Johns Hopkins UniversityStrongly Connected ComponentsStudy the two-pass DFS algorithm after the small-graph examples.

Finished this module? Mark it done.

Comments

Stuck on something, spotted a mistake, or found a resource that helped you? Tell us below.

Loading comments