← Topo Sort · guided lesson

Topological Sort

1 / 18 · story

the story

Topological sort with Kahn's algorithm

Every tool here exists because something was too slow or broke without it. Here is what.

1962 · A. B. Kahn (Westinghouse Electric Corporation, Baltimore)

In the late 1950s, big projects such as the US Navy's Polaris missile programme were planned as PERT networks: thousands of events, each waiting for others. Before a computer could analyse such a network, the events had to be listed so that every event came after the ones it waits for. In 1962 A. B. Kahn published "Topological sorting of large networks" in Communications of the ACM. He estimated that, on an IBM 7090, a 30,000-activity PERT network could be ordered in under an hour of machine time — though, as he noted, the method had not yet been programmed.

the problem it solved

Putting thousands of dependent events in a valid order — and noticing when the dependencies loop.

why it matters: without it

Builds, spreadsheets and schedulers would have to guess an order and retry, and a circular dependency would hang instead of failing with a clear error.

sources: Kahn — Topological sorting of large networks (CACM, 1962) ↗ · Malcolm, Roseboom, Clark & Fazar — Application of a Technique for Research and Development Program Evaluation (Operations Research, 1959) ↗ · Knuth — The Art of Computer Programming, Vol. 1, §2.2.3 (topological sorting) ↗

also in this chapter: Topological order by DFS (reverse post-order) · Critical path (DP on a DAG) · Tree centre by peeling leaves