DSA · Reimagined
Graphs medium time O(V + E) space O(V)

Topological Sort

Kahn's algorithm counts how many prerequisites each node has. Anything with zero is ready to go; taking it removes one prerequisite from each of its successors, which may make them ready too. If everything comes out, the graph had no cycle.

A0B0C2D1E1F2
ready (indegree 0)
A
0
B
1
topological orderempty

Count each node’s prerequisites — the number under it is its indegree.

1 / 15
A fixed scene — scrub through it, or open the code.

Practice

Machine twin: /dsa-viz-v2/topological-sort.json — the full deterministic run as structured data.