Concept Flow - Topological Sort Using Kahn's Algorithm BFS
Calculate in-degree of all nodes
Add nodes with in-degree 0 to queue
While queue not empty
Pop node from queue
Add node to topological order
For each neighbor
Decrease in-degree of neighbor
If in-degree becomes 0, add neighbor to queue
Repeat until queue empty
Check if topological order includes all nodes
Return topological order or error if cycle
This flow shows how Kahn's algorithm uses in-degree counts and a queue to build a topological order by repeatedly removing nodes with zero in-degree.
