Core idea
Topological sort works only on directed acyclic graphs.
It is useful for dependency scheduling and build order problems.
Kahn's algorithm repeatedly removes vertices with zero incoming edges.
How it works
- Compute indegree for each vertex.
- Push all zero-indegree vertices into a queue.
- Remove one vertex and append it to the order.
- Decrease indegree of its neighbors.
- Repeat until all vertices are ordered.