Use BFS when…
The problem asks for shortest path in an unweighted graph, level-by-level traversal, minimum number of steps, or multi-source spread (like Rotting Oranges). BFS guarantees the shortest path because it explores neighbors layer by layer. The queue naturally enforces this order.
Use DFS when…
The problem asks whether a path exists, asks you to explore all possibilities (backtracking), involves topological sort, or requires detecting cycles. DFS is also simpler to implement recursively for tree problems and uses less memory when the graph is wide and shallow.
Use Union-Find when…
The problem involves repeatedly merging groups (accounts merge, satisfiability of equality equations) or detecting whether adding an edge creates a cycle (redundant connection). Union-Find with path compression and union by rank gives near-O(1) operations — far faster than running BFS/DFS repeatedly.
Quick reference table
Shortest path (unweighted) → BFS. Shortest path (weighted, non-negative) → Dijkstra (min-heap + BFS). Cycle detection (undirected) → Union-Find. Cycle detection (directed) → DFS with 3-colour states. Connected components → BFS/DFS or Union-Find. Topological order → Kahn's BFS or DFS post-order. All paths / backtracking → DFS.