← All Tools

Topological Sort Visualizer

Paste an edge list — one A → B, A B, or A: B C D per line — and Kahn's algorithm produces a valid topological ordering, step by step. The visualizer also computes in-degrees, level layers (Coffman–Graham style), spots cycles with the offending node set, and emits a Graphviz .dot diagram you can drop into dot -Tsvg.

Result

Parallel-execution layers

Each layer is a set of nodes whose dependencies are all in earlier layers — i.e. everything in a layer can run in parallel. Useful for job-runner schedulers, build pipelines, and ETL DAGs.

Step trace

Kahn's algorithm picks any node with in-degree 0, emits it, and decrements the in-degree of its successors. We break ties with the rule above so the trace is reproducible.

Graphviz DOT export

Copy this into a .dot file and run dot -Tsvg graph.dot -o graph.svg. Edges in the topological order are coloured to make the flow easier to follow; cycle edges are highlighted.


About topological sort

A topological sort of a directed graph is an ordering of nodes where every edge u → v places u before v. It only exists if the graph is a DAG (directed acyclic graph) — a cycle makes the order undefined. Kahn's algorithm (1962) is the iterative version: collect every node with in-degree 0, emit them, remove their outgoing edges, repeat. The depth-first variant produces the order by post-order traversal in reverse. Both run in O(V + E).

Where you'll meet it: build systems (Make, Bazel, Nix), package managers (npm, Cargo), task schedulers (Airflow, Dagster, Tekton), course prerequisites, spreadsheet recalc, linker symbol resolution, and data-flow IRs in compilers. If a build complains about a "circular dependency," it ran a topological sort and gave up at the surviving nodes — the same ones this tool will highlight.