Overview
Topological Sort processes a DAG by repeatedly choosing nodes whose incoming prerequisites are already satisfied, or by reversing DFS finishing order.
Orders the nodes of a directed acyclic graph so every prerequisite appears before its dependents.
Compact metadata for implementation and discovery.
Topological Sort processes a DAG by repeatedly choosing nodes whose incoming prerequisites are already satisfied, or by reversing DFS finishing order.
Quick facts
Runtime and memory behavior at a glance.
Best
O(V + E)
Average
O(V + E)
Worst
O(V + E)
Space
O(V)
Show dependencies being removed as nodes enter the output order.
Topological sorting is defined only for directed acyclic graphs.
What each reference supports for this entry.
Textbook reference for the algorithmic family and analysis of Topological Sort.
Good next jumps from the relationship graph, ranked for useful discovery.
Pathfinding · Core
Acyclic shortest paths relax vertices in topological order.
Compare with thisScheduling · Core
Critical Path Method uses topological order on the activity DAG.
Compare with thisGraph Traversal · Core
Dynamic programming on DAGs processes states in topological order so dependencies are solved first.
Compare with thisGraph Traversal · Foundation
DFS finishing order is a common way to compute topological order.
Compare with thisAcyclic shortest paths relax vertices in topological order.
Topological ordering is defined for directed acyclic graphs.
Kahn's Algorithm is one specific topological sorting method.