When NOT to Use

Avoid forcing this pattern

Avoid forcing this pattern when:

  • Shortest path needed: DFS doesn't guarantee shortest paths. Use BFS for unweighted or Dijkstra for weighted graphs.
  • Level-by-level processing required: When distance from source matters, BFS is more natural.
  • deep graphs with shallow solutions: DFS might explore deep paths when answer is shallow. Consider BFS or iterative deepening. 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.