Topological Sort
12 problems · 8 with full explanations
0 Easy6 Medium3 Hard
Topological sort produces a linear ordering of a DAG where each node comes before its descendants. Two algorithms: DFS (post-order reversal) and BFS Kahn's (process nodes with in-degree 0). Applications: course scheduling, build dependency resolution, and task ordering.
How to practice
To practice Topological Sort problems effectively, start with the Easy problems listed below, trace through each solution on paper, then re-implement without looking. When you can recognise the topological sort pattern within 30 seconds of reading a new problem, move on to Medium difficulty. Use the related topic pages and our study guide for a structured progression.
All Topological Sort problems
- 210.Course Schedule IIMedium
- 310.Minimum Height TreesUnknown
- 329.Longest Increasing Path in a MatrixHard
- 802.Find Eventual Safe StatesMedium
- 851.Loud and RichMedium
- 1462.Course Schedule IVMedium
- 1857.Largest Color Value in a Directed GraphHard
- 1976.Number of Ways to Arrive at DestinationMedium
- 2115.Find All Possible Recipes from Given SuppliesUnknown
- 2127.Maximum Employees to Be Invited to a MeetingUnknown
- 2192.All Ancestors of a Node in a Directed Acyclic GraphMedium
- 2392.Build a Matrix With ConditionsHard