GraphsEvidence Contributing

Topological Sort

Order nodes of a DAG so every directed edge points from earlier to later, via DFS post-order or Kahn's algorithm.

Practice Problems: 3
Difficulty: 0 Easy·2 Medium·1 Hard

Algorithmic Intuition & Recognition

The Topological Sort technique is applied when tackling problems characterized by specific invariants in the problem state or constraints:

  • Core Strategy: Order nodes of a DAG so every directed edge points from earlier to later, via DFS post-order or Kahn's algorithm.
  • When to use: Look for opportunities where repeated re-computation can be replaced by maintaining monotonic properties, state windows, or relational pointers.
  • Interview Signal: Demonstrating this pattern shows mastery of Graphs foundations, reducing worst-case algorithmic complexity.

Canonical Practice Problems

3 problems

Curated Sheets Containing This Pattern

Related Algorithmic Patterns