Topological Order Generator
A topological order lists tasks so that every dependency comes before the thing that needs it. What the usual worked example hides is how much freedom is left over: most dependency graphs admit an enormous number of valid orders, and a few admit exactly one. This page gives you an order, checks every edge points forwards in it, and — while the node count allows — counts precisely how many other valid orders exist.
What this generator does
Builds a random directed acyclic graph by only ever pointing edges forwards in a hidden permutation, so a cycle is impossible by construction. Kahn's algorithm then produces an order, every edge is checked to run forwards in it, and at nine nodes or fewer every linear extension is enumerated to give an exact count of the alternatives.
How to use this tool
- Choose how many tasks and how densely to add dependencies.
- Work out an order yourself: repeatedly take any task whose prerequisites are all done.
- Generate, and check your order against the edge list.
- Read the count of valid orders — yours is probably not the one shown, and that is fine.
Understanding the controls
- How many tasks
- Between 4 and 12. The exact count of valid orders runs up to nine tasks; above that the page says so rather than guessing.
- Extra edge density (%)
- How likely each forward pair becomes a dependency. More dependencies mean fewer valid orders and less freedom.
- Seed
- Any word reproduces the same dependency graph and the same order.
Common use cases
- Teaching topological sorting with the number of valid answers made explicit
- Build-order and task-dependency worked examples
- Test instances for a scheduler that must respect prerequisites
- Showing why 'the' topological order is usually the wrong phrase
- Setting a reproducible exercise from a seed
How this generator works
Kahn's algorithm repeatedly takes a task with no unmet prerequisites, removes it, and decrements its dependents. The check works from the definition rather than the algorithm: every edge must have its source earlier than its target in the finished order, and the order must be a permutation of the tasks. The count of alternatives is a separate exhaustive walk that places every legal task at every step, bounded so a wide graph cannot run away.
Randomness and fairness
The dependency graph is random; the order is computed and then verified. A seed reproduces the graph exactly and is therefore explicitly not cryptographically secure. Without a seed the browser's cryptographically secure generator is used.
For how randomness is produced across the whole site, see how Generate Random works.
Limitations and good to know
- The exact count of valid orders stops above nine tasks, where the enumeration becomes too large.
- Ties are broken by node index, so the order shown is one specific valid answer of many.
- Cycles never occur here by construction — this page is about ordering, not about detecting them.
- Dependencies carry no durations, so this is an order rather than a schedule.
- Graphs are not stored between visits; seed one you want again.
Privacy and your data
Everything is computed in your browser. Nothing about the dependencies or your seed is transmitted or kept.
Related generators
- Strongly Connected Components GeneratorDirected graphs partitioned into strongly connected components by Kosaraju, checked against mutual reachability computed from every node.
- DAG GeneratorDirected acyclic graphs where the absence of cycles is structural rather than checked afterwards — for testing schedulers, build systems and topological sorts.
- Graph Traversal GeneratorThe same graph visited breadth-first and depth-first side by side, with the hop count each node sits at.
- Bipartite Matching GeneratorPeople-to-slots problems solved to the largest possible matching, with the answer proved by building a minimum cover of the same size.
- Random Graph GeneratorRandom graphs at a density you choose, drawn and exported as an edge list or DOT, with connectivity measured rather than assumed.