algorythms
All Patterns
Pattern 15

Topological Sort

Topological Sort

Order nodes in a DAG such that every directed edge goes from earlier to later. Use BFS (Kahn's algorithm) with in-degree tracking or DFS with a finish-time stack.

Time

O(V + E)

Space

O(V + E)

Recognize it when

  • Task scheduling with prerequisites
  • Course prerequisites / build order
  • Detect cycles in directed graph
Progress0/4
0 solved0 attempted