What are the practical factors to consider when choosing between Depth-First Search (DFS) and Breadth-First Search (BFS)? [closed]

That heavily depends on the structure of the search tree and the number and location of solutions (aka searched-for items).

  • If you know a solution is not far from the root of the tree, a
    breadth first search (BFS) might be better.

  • If the tree is very deep and solutions are rare, depth first search
    (DFS) might take an extremely long time, but BFS could be faster.

  • If the tree is very wide, a BFS might need too much memory, so it
    might be completely impractical.

  • If solutions are frequent but located deep in the tree, BFS could be
    impractical.

  • If the search tree is very deep you will need to restrict the search
    depth for depth first search (DFS), anyway (for example with
    iterative deepening).

But these are just rules of thumb; you’ll probably need to experiment.

I think in practice you’ll usually not use these algorithms in their pure form anyway. There could be heuristics that help to explore promising parts of the search space first, or you might want to modify your search algorithm to be able to parallelize it efficiently.

Leave a Comment