Overview
Kahn's algorithm tracks indegrees in a directed graph and emits nodes whose prerequisites have all been removed, making cycles visible when nodes remain unprocessed.
Produces a topological ordering by repeatedly removing nodes with no incoming edges.
Compact metadata for implementation and discovery.
Kahn's algorithm tracks indegrees in a directed graph and emits nodes whose prerequisites have all been removed, making cycles visible when nodes remain unprocessed.
Quick facts
Runtime and memory behavior at a glance.
Best
O(V + E)
Average
O(V + E)
Worst
O(V + E)
Space
O(V)
in_degree[v] = in_degree[v] - 1Updates a neighbor after one incoming prerequisite edge is removed.
Highlight active nodes, discovered edges, and the graph structure produced by each step.
Kahn's Algorithm should be used with the assumptions and tradeoffs of topological Ordering in mind.
What each reference supports for this entry.
Textbook support for Kahn's Algorithm's standard algorithm design, invariants, and complexity analysis.
Open sourceAlgorithm catalog support for Kahn's Algorithm's problem context, known alternatives, and practical selection tradeoffs.
Open sourceGood next jumps from the relationship graph, ranked for useful discovery.
Kahn's Algorithm expects the graph to be acyclic for a complete ordering.
Kahn's Algorithm computes a topological order by repeatedly removing zero-indegree vertices.