Fundamentals · Hard · Free
What is topological sort? Where is it used (build systems, tasks)?
FresherFundamentalsData Structures & Algorithms
Topological sort
Linear ordering of DAG where every edge u→v has u before v. Kahn's (BFS indegree) or DFS postorder.
- Build systems task dependencies
- Course prerequisite scheduling
- Detect cycle if not all nodes processed
java
// Kahn: queue nodes with indegree 0, reduce neighbor indegreeSay DAG requirement—cycle means no valid topo order.