Kahn's Algorithm
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
Place 0, position 1. Its edges to 1, 2 are satisfied, so their counts drop. 1, 2 reached 0 and are ready.
What you will see
In-degree counters on vertices; zero-in-degree vertices enter a queue; removing one decrements its targets.
Cost
| Best | O(V + E) |
|---|---|
| Average | O(V + E) |
| Worst | O(V + E) |
| Space | O(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.
Before this
Taught by the same lesson
Topological Sort covers these too, in the same run.