DDSA Solutions

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.

Open the full study guide →

All Topological Sort problems