Topological sort
medium 20 minA topological sort lists the nodes of a directed graph so that every edge u → v has u before v: a valid order for tasks with prerequisites.
Where it shows up
The same pattern appears across everyday software.
Course planning
Degree planners order courses so prerequisites come first and group them into the fewest semesters, which is Kahn's algorithm by levels.
Build systems
make, Bazel, Gradle and Webpack build a dependency graph of targets or modules, compile them in topological order, run independent ones in parallel and report a cycle as a circular dependency.
Package managers
npm, pip and apt resolve which packages a project needs and install each one after its dependencies, a DFS post-order over the "depends on" graph.
Workflow and ETL schedulers
Apache Airflow and similar tools model each pipeline as a DAG of tasks and only start a task once every upstream task has succeeded.
Spreadsheet recalculation
When a cell changes, the spreadsheet recomputes dependent formulas in topological order so each formula reads already-updated inputs; a loop is reported as a circular reference.
Database migrations and startup order
Migration tools and service managers such as systemd order steps or services by their declared dependencies, so a table or service exists before anything that needs it.