← All tools

Topological Sort

Compute a topological ordering of a directed acyclic graph — the order in which to run tasks so every dependency precedes its dependents. Enter edges and the tool returns a valid order (the lexicographically smallest one), reports unreachable nodes, and detects cycles. Everything runs locally in your browser.

Edges

Edges / nodes

One rule per line. A B means A must come before B (A is a prerequisite of B). A chain A B C means A before B before C. A single token on a line declares a node with no dependencies. Blank lines and # comments are ignored.

Result

Topological sorting labels each node of a directed acyclic graph with an order index such that for every edge A → B, A's index is less than B's. It is the classic way to schedule tasks with dependencies: build steps, course prerequisites, package installation. This tool uses Kahn's algorithm (repeatedly remove a node with no incoming edges); by always choosing the lexicographically smallest available node it returns the lexicographically smallest valid order, which is unique for a given graph. If no node has zero in-degree while nodes remain, the graph contains a cycle and no valid ordering exists. Pairs with the Shortest Path (Dijkstra) and Graph tools. Everything runs locally — nothing leaves your browser.