Skip to main content
Back to the DSA atlas
Graphs Algorithm Advanced

Tarjan SCC

Find strongly connected components in one DFS by tracking discovery times, low-link values, and the active stack.

graphsscclow-linkrare

Interactive visualization

Use the controls to connect the idea to concrete operations before diving into the full write-up.

Step 1 / 6

nodedisclow
000
1--
2--
3--
4--
5--

Tarjan stack

0

Low-link values decide SCC roots

Start DFS at 0 and push it onto the stack.

Family

Graphs

Nodes, edges, traversal, connectivity, and shortest paths.

Builds on

2 topics

Read these first if you want the surrounding context.

Unlocks

0 next topics

Use these follow-ups when you want to apply the current idea in a richer setting.

Learning paths

2

This topic appears in curated progressions so you can keep moving without guessing the next step.

Problem

In a directed graph, a strongly connected component is a maximal set of vertices where every node can reach every other node.

You want to partition the graph into these SCCs efficiently.

Core idea

Tarjan runs one DFS and maintains:

  • disc[u]: discovery time
  • low[u]: earliest discovery time reachable while staying inside the current DFS stack context
  • a stack of nodes that belong to the current unresolved SCCs

When low[u] == disc[u], node u is the root of one SCC, so everything on the stack up to u pops together.

Why it works

The stack represents nodes still “open” in the DFS search tree. Low-link values tell you whether a subtree can reach an ancestor that is also still open.

If it cannot, that subtree has just closed into one SCC.

Algorithm sketch

  1. DFS into an unvisited node
  2. assign disc and low
  3. push the node onto the active stack
  4. update low from tree edges and back edges to nodes still on the stack
  5. when low[u] == disc[u], pop one whole SCC

Complexity

OperationTime
Full SCC decompositionO(V+E)O(V + E)

Key takeaways

  • Tarjan finds SCCs in one DFS pass
  • The stack matters: only edges to nodes still on the stack can shrink low-link values for SCC detection
  • low[u] == disc[u] means “this node closes a component”
  • This is a rare advanced graph topic, but it is foundational for serious directed-graph work

Practice problems

ProblemDifficultyKey idea
Planets and Kingdoms🔴 HardBuild SCC decomposition
Calling Circles🔴 HardClassic SCC grouping
2-SAT references🔴 HardSCCs on implication graphs

Relation to other topics

  • DFS supplies the search tree and timestamps
  • Topological Sort often appears after SCC condensation into a DAG
  • Bridges & Articulation Points use related low-link ideas, but on undirected graphs

Build on these first

These topics supply the mental model or underlying structure that this page assumes.

Related directions

These topics live nearby conceptually, even if they are not direct prerequisites.

More from Graphs

Stay in the same family when you want parallel variations of the same mental model.

Paths that include this topic

Follow one of these sequences if you want a guided next step instead of open-ended browsing.

From the blog

Pair the atlas with recent writing from the rest of the site when you want a broader engineering perspective alongside the topic graph.