Topological sort calculator
Order the vertices of a directed graph so every arc points forward. Enter directed arcs ("A -> B") and the tool runs Kahn's algorithm with lexicographic tie-breaking and a DFS post-order, returning both valid orderings. If the graph contains a cycle it is not a DAG — the tool detects it and shows the offending cycle.
Related tools
All Discrete maths & graphs tools →Topological sort calculator works straight from this page — free, instant, nothing to install. It sits under Discrete maths & graphs in our catalogue, alongside Bitwise Calculator and Delaunay triangulation generator.
How to use it
- Open the tool — no signup or install needed.
- Enter your input or adjust the available options.
- Get your result instantly, then copy or download it.
Frequently asked questions
What does Topological sort calculator do?
Order the vertices of a directed graph so every arc points forward. Enter directed arcs ("A -> B") and the tool runs Kahn's algorithm with lexicographic tie-breaking and a DFS post-order, returning both valid orderings. If the graph contains a cycle it is not a DAG — the tool detects it and shows the offending cycle.
What does a concrete case look like?
A→B, A→C, B→D, C→D → A, B, C, D — the tool shows every step in between, not just the final figure.
When would I actually use this?
Anything modelled as points and connections: a shortest route, a network's capacity, a schedule with dependencies, or a circuit reduced to its logic.
What is the most common mistake?
Assuming a shortest path stays shortest when a weight changes sign. Negative edges break the greedy argument Dijkstra rests on, and the algorithm returns a confident wrong answer rather than an error.
What else is filed next to it?
Bitwise Calculator, Delaunay triangulation generator and Dijkstra shortest path calculator share its section. They are not variants of it — being filed together is not the same as being alike — but that is where to look if this turned out not to be the tool you wanted.
Where do the figures come from?
The algorithms are the textbook ones and their results are exact for the graph you enter. What varies is cost: several of these problems have no known efficient solution, so large inputs are answered by heuristic and the tool says when that is the case.