views:

94

answers:

2

Hello

Both can be used to find the shortest path from single source. BFS runs in O(E+V) while Dijkstra's runs in O((V+E)*log(V))

But I've seen Dijkstra used a lot like in routing protocols

+7  A: 

Dijkstra allows assigning distances other than 1 for each hop. For example in routing the distances (or weights) can assigned by speed, cost, operator preference, etc. The algorithm then gives you the shortest path from your source to every node in the traversed graph.

Meanwhile BFS basically just expands the search by one “hop” (link, edge, whatever you want to call it in your application) on every iteration, which happens to have the effect of finding the smallest number of hops it takes to get to any given node from your source (“root”).

Arkku
+1  A: 

Dijkstra generates, as part of its algorithm, a set of distances from your node to each other node.

BFS does not.

If you want the ability to know "this node is the next-closest one if the current closest is lost", BFS won't do it for you.

Borealid