AlgoScope

Kahn's Algorithm

AlgorithmintermediateTopological Sort

Repeatedly place a vertex with in-degree zero and lower the counts of everything it points to.

Decision · step 2 of 8Topological Sort: Kahn's algorithm
011020324151u

Place 0, position 1. Its edges to 1, 2 are satisfied, so their counts drop. 1, 2 reached 0 and are ready.

Open in the player →or start at step 2

What you will see

In-degree counters on vertices; zero-in-degree vertices enter a queue; removing one decrements its targets.

How topological sort works →

Cost

BestO(V + E)
AverageO(V + E)
WorstO(V + E)
SpaceO(V)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.

Screen readers: Vertices announce name, discovery numbers where relevant and component; each step announces the structural conclusion (bridge found, component closed).

Reduced motion: Component colouring and ordering changes crossfade in place.

Leads to

Topics that need this one first.

Taught by the same lesson

Topological Sort covers these too, in the same run.