6

I've read that the BFS algorithm is better suited to parallel implementation than DFS. I'm having trouble grasping the intuition of why this should be true. Can anyone explain?

Thanks

azphare
  • 497
  • 4
  • 11

2 Answers2

3

BFS is a procedure of propagating frontiers. 'Propagate' means push all their unvisited adjacent vertices into a queue, and they can be processing independently.

in DFS, the vertices are visited one by one along a direction such as A->B->C. Visiting B must occur before visiting C. It's a sequential procedure which can not be parallelized easily.

But the truth is both BFS and DFS are hard to parallelize because all the processing nodes have to know the global information. Accessing global variables always requires synchronizations and communications between nodes.

onesuper
  • 196
  • 2
  • 7
  • It isn't a search unless the space has branches. It is straighforward (with the right language/tools) to fork when branches are found, giving parallel DFS searches. Communication can be limited to passing information "up" the tree and that can be done without locks on the data; simply hold an array of answers, one per branch, and have the parent wait until the child searches are complete (which is what happens in DFS anyway). Virtually all the high performance chess programs do this. – Ira Baxter May 30 '12 at 14:08
  • ... with an average branch factor of 2, a DFS space that is 10 deep has 2^10 branches... that's a huge amount of potential parallelism. Even average branching factors well under 2 will produce interesting parallelism in such a search. – Ira Baxter May 30 '12 at 14:15
0

There a some good informations about DFS and BFS in general:

Especially the animation shows how BFS use more parallel concepts. I think BFS could be implemented parallel, but there is no parallel solution for DFS. DFS is a linear algorithm who calls every child once.

pearcoding
  • 1,149
  • 1
  • 9
  • 28