3.5.8 · D1Graphs

Foundations — Strongly Connected Components (SCC) — Kosaraju's algorithm, Tarjan's algorithm

1,718 words8 min readBack to topic

Before you can understand Kosaraju or Tarjan, you need to see every piece of notation they lean on. This page builds each one from nothing, in the order the topic uses it. Nothing here is optional — the parent note silently assumes all of it.


1. A directed graph — the playing field

Picture cities joined by one-way streets. The arrow is the direction of legal travel.

Figure — Strongly Connected Components (SCC) — Kosaraju's algorithm, Tarjan's algorithm
  • The symbol means "there is an edge from node to node ."
  • We write for the number of vertices and for the number of edges. When you see complexity later, it just means "work proportional to how many nodes plus how many arrows there are."

Prerequisite: if the words node and edge are new, skim Depth First Search first — it walks these graphs.


2. A path and the squiggly arrow

The straight arrow is one edge. The squiggly arrow is any number of edges strung together (possibly through other nodes).


3. Mutual reachability — the heart of "strongly connected"

Figure — Strongly Connected Components (SCC) — Kosaraju's algorithm, Tarjan's algorithm

Look at the figure: the green cycle lets every node reach every other node and return, so all three are mutually reachable — they form one SCC. The lone orange node can be reached but you can never drive back, so it sits in its own SCC.

Every node belongs to exactly one SCC (even if that SCC is just itself). This "partition the whole graph" fact is what lets us later shrink each group to a single dot.


4. Depth-First Search (DFS) — the engine both algorithms ride

Figure — Strongly Connected Components (SCC) — Kosaraju's algorithm, Tarjan's algorithm

Two moments in a node's life matter, and the SCC algorithms name both:

  • visited[u] — a true/false flag: "have we touched yet?"
  • low[u] (Tarjan only) — a running "earliest node I can loop back to"; we build its full meaning in the D-later pages, but know now it is another number stored per node, computed during DFS.

Full walkthroughs live in Depth First Search.


5. The stack — Tarjan's memory of "still in play"


6. DAG and condensation — the payoff

Figure — Strongly Connected Components (SCC) — Kosaraju's algorithm, Tarjan's algorithm

7. Big-O and the reversed graph — two last symbols


Prerequisite map

Directed graph: nodes and one-way edges

Path and reachability u to v

Mutual reachability both directions

SCC maximal mutually reachable group

Depth First Search

Discovery time and finish time

Stack and onStack flag

Kosaraju two passes

Tarjan one pass

Condensation is a DAG

Topological Sort and easy DAG problems


Equipment checklist

Cover the right side and test yourself.

What does the arrow mean?
A single directed edge — legal travel from to only, not back.
What does the squiggle mean?
There exists some path (any number of edges) from to ; can reach .
When are two nodes in the same SCC?
When they are mutually reachable: both and .
What does "maximal" add to the SCC definition?
You cannot include any extra node without breaking the round-trip property.
What is f(u), the finish time, and when is it recorded?
The step when DFS leaves for the last time — recorded on the way back up, after all descendants finish.
What is the difference between visited[u] and onStack[u]?
visited = seen ever; onStack = seen and still part of the SCC currently being built.
What is and what stays the same after flipping?
The graph with every edge reversed; within-SCC reachability is unchanged, but between-SCC direction flips.
Why is the condensation always a DAG?
A cycle among super-nodes would mean those SCCs reach each other both ways, so they'd already be one SCC.
What does promise?
Running time grows in proportion to the number of nodes plus edges — linear in the graph's size.