Topological sort starts with zero-indegree nodes in a directed acyclic graph. Removing one node from the queue emits it and lowers the indegree of its outgoing neighbors.
If nodes remain after the queue empties, the graph contains a cycle. Several valid orders can exist when multiple nodes become ready together.
When to use
Use it to order build steps, prerequisites, or dependent jobs.