Concept Flow - Topological Sort Using Kahn's Algorithm BFS
Calculate in-degree for each node
Add nodes with in-degree 0 to queue
While queue not empty
Yes
Pop node from queue
Add node to topological order
For each neighbor of node
Decrease neighbor's in-degree by 1
If neighbor's in-degree is 0, add to queue
↩Back to While queue not empty
Start by counting incoming edges for each node. Nodes with zero incoming edges go into a queue. Remove nodes from the queue, add them to the order, and reduce in-degree of their neighbors. Repeat until all nodes are processed.
