Skip to content
Commitwise
Menu

Topological sort

An order of a directed graph's nodes where every edge points forward, used for dependencies.

Definition

In a topological order, every node comes after all the nodes it depends on. It exists only when the directed graph has no cycles. Kahn's algorithm repeatedly takes nodes with no remaining incoming edges; if some nodes are never taken, they are part of a cycle. Build tools, package managers and course planners rely on it.

In practice

With "course 0 before 1" and "course 1 before 2", a valid order is 0, 1, 2.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.