Topological Sort
Put tasks in an order where every task comes after the ones it depends on, and discover at the same time whether such an order is even possible.
After this lesson you will be able to
- Describe a dependency problem as a directed graph and recognise a DAG (directed acyclic graph).
- Explain why a valid ordering exists exactly when there is no cycle.
- Compute a topological order with Kahn's algorithm (in-degrees and a queue) and with DFS (reverse finishing order).
- Detect cycles with either method, and explain what the leftover nodes mean.
- Extend the idea to longest-path problems on a DAG (earliest finish times).
Before you start. BFS (queue) and DFS (recursion and visited states). Graphs, for directed edges and in-degree.