dfs-vs-bfs

Installation
SKILL.md

When to use

DFS (stack/recursion) explores one branch fully before backtracking. BFS (queue) explores level-by-level.

Rules

  • If the problem asks "shortest" or "minimum steps" on an unweighted graph, ALWAYS choose BFS
  • If it asks "all paths," "can we reach," or "count islands," DFS is simpler
  • NEVER use BFS for cycle detection — DFS is the right tool
  • Both visit each node once: O(V+E) time

DFS use cases

Cycle detection, topological sort, path existence, connected components, backtracking puzzles, flood fill.

BFS use cases

Shortest unweighted path, level-order traversal, nearest neighbor, minimum steps.

Installs
4
Repository
knoopx/pi
GitHub Stars
59
First Seen
May 24, 2026
dfs-vs-bfs — knoopx/pi