When To Use BFS
Here are a few scenarios and pointers on when to prefer BFS
over DFS:
- When you need to find the shortest path between any two nodes in an unweighted graph.
- If you're solving a problem, and know a solution is not far from the root of the tree,
BFS
will likely get you there faster. - If the tree is very deep,
DFS
with heuristics might be faster.