- Home
- /
- Tutorials
- /
- DSA Tutorial
- /
- Topological Sort
Graphs
Topological Sort
Any question about ordering things with dependencies is a topological sort. Course prerequisites, build steps, module imports, task schedules - same problem, different nouns.
What it produces
An ordering of a directed graph where every node appears before everything that depends on it. It only exists if there are no cycles - and detecting that impossibility is half the value.
Kahn's algorithm
Count how many things each node is waiting on. Start with those waiting on nothing. As each one completes, decrement its dependents; any that reach zero become available.
Kahn's algorithm
javascript
