AlgoViz

Topological sort

medium 20 min

A 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.

Chapter mnemonic

Kahn’s topological sort

Bake what is ready. Cross it off. Unlock the next recipe.

The ready queue is empty, and three recipes remain. What does that tell you?

The remaining dependencies contain a cycle. A full topological ordering is impossible.