When NOT to Use

Avoid forcing this pattern

Avoid forcing this pattern when:

  • Undirected graph: Topological sort only applies to directed graphs. Use BFS/DFS for undirected.
  • Graph has cycles: No valid topological order exists.

Detect cycle first or use different approach.

  • Order doesn't matter: If dependencies don't constrain order, simpler iteration suffices. Remember: forcing a pattern where it doesn't fit leads to overcomplicated solutions. If you find yourself fighting the approach, step back and reconsider whether another technique works better.