Advanced maths

Strongly connected components calculator for a directed graph

Partition a directed graph into mutually reachable components, retaining isolates and returning the acyclic component condensation edges.

Your numbers

Use at most 200 rows with one-based vertex labels. Direction matters; blank means every vertex is an isolate.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Strong connectivity preserves edge direction. Two vertices belong to the same component when each can reach the other through directed paths, possibly using other vertices in that component. This page partitions all declared vertices, labels the components by their smallest original vertex and lists cross-component edges once. It checks that the resulting condensation graph is acyclic, which separates cyclic internal structure from the one-way relation between components.

THE FORMULAu and v belong to one SCC exactly when u reaches v and v reaches u; contracting each component gives a directed acyclic graph.

A worked example

With mutual edges between one and two, mutual edges between three and four, and links 2→3 and 4→5, the components are {1,2}, {3,4} and {5}. Their condensation is C1→C2→C3. Vertex five does not need a self-loop to form a singleton component: every vertex reaches itself through a zero-length path. Adding an isolate would add another singleton, even if it appeared in no edge row.

Good to know

Directed graphs with 1–40 vertices and at most 200 rows. Loops and duplicate edges are allowed; duplicate cross-component relations are merged. Labels follow smallest original vertex and are not promised to be a topological ordering. A singleton need not contain a nontrivial directed cycle. This is strong connectivity, not connectivity after erasing directions, and does not rank components by centrality or detect failures under vertex removal.

One-way access joins weak components without merging strong ones

The default edge 2→3 lets the first pair reach the second pair, but there is no directed path back. They therefore remain separate strong components even though ignoring arrowheads would place them in one connected region. A network diagram can look visually continuous while hiding that difference. The component table and directed condensation list make the actual mutual-reachability requirement inspectable.

The implementation performs a finishing-order traversal and a traversal on reversed edges to collect the strong components. Original vertex labels are retained and sorted inside each part. The resulting partition includes every declared vertex exactly once. A self-loop changes local edge structure but does not create a new component, and repeated copies of a directed edge do not change which vertices can reach one another.

Mutually reachable vertex groups collapse to a three-node directed acyclic graphC1: {1,2}C2: {3,4}C3: {5}Condensation: C1 → C2 → C3Internal cycles remain inside their components
Components C1={1,2}, C2={3,4}, C3={5} retain mutual internal reachability. Edges 2→3 and 4→5 become C1→C2→C3. There is no path back between these components.

The Topological sort calculator for a directed acyclic graph can order the acyclic condensation after components are contracted.

Condensation removes internal cycles but does not choose a preferred original path

If the component graph contained a directed cycle, each component on that cycle could reach every other, so they should have been one strong component. The condensation is therefore acyclic, and the engine checks that invariant explicitly. Internal edges are omitted from its edge list; several original edges connecting the same ordered pair of components produce one relation. The compact graph describes reachability between groups rather than reproducing every original edge identity.

Component numbers are assigned by the smallest member label for readability. They are not a guarantee that C1 precedes C2 in a valid topological ordering; the original labels can point in the opposite direction. A singleton component also need not represent a feedback loop, because zero-length self-reachability is enough. To identify only vertices on nontrivial cycles, an additional size-or-self-loop test would be needed instead of treating every singleton as cyclic.

A few questions, answered

Can a graph have one SCC without an edge between every pair?

Yes. Strong connectivity requires directed paths, not a direct edge for each ordered vertex pair. Intermediate vertices can provide the reachability.

Does reversing all edges change the SCC partition?

No. Mutual reachability remains mutual after reversal, although the directions of condensation edges reverse. Individual one-way reachability relations do change.

Find your calculator

Start typing to explore the library.