Why use Dijkstra's algorithm instead of Best (Cheapest) First Search?

和自甴很熟 提交于 2019-12-03 09:27:29

问题


From what I have read so far. The Best First Search seems faster in terms of finding the shortest path to the goal because Dijkstra's algorithm has to relax all the nodes as it traverses the graph. What makes Dijkstra's algorithm better than Best First Search?


回答1:


EDIT: Your edit clarifies you are interested in Best-First Search, and not BFS.

Best-First Search is actually an informed algorithm, which expands the most promising node first. Very similar to the well known A* algorithm (actually A* is a specific best-first search algorithm).

Dijkstra is uninformed algorithm - it should be used when you have no knowledge on the graph, and cannot estimate the distance from each node to the target.

Note that A* (which is a s best-first search) decays into Dijkstra's algorithm when you use heuristic function h(v) = 0 for each v.

In addition, Best First Search is not optimal [not guaranteed to find the shortest path], and also A*, if you do not use an admissible heuristic function, while Dijkstra's algorithm is always optimal, since it does not relay on any heuristic.

Conclusion: Best-First Search should be prefered over dijkstra when you have some knowledge on the graph, and can estimate a distance from target. If you don't - an uninformed Best-First Search that uses h(v) = 0, and relays only on already explored vertices, decays into Dijkstra's algorithm.
Also, if optimality is important - Dijkstra's Algorithm always fit, while a best-first search algorithm (A* specifically) can be used only if an appropriate heuristic function is available.


Original answer - answering why to chose Dijkstra over BFS:

BFS fails when it comes to weighted graphs.

Example:

     A
   /   \
  1     5
 /       \
B----1----C

In here: w(A,B) = w(B,C) = 1, w(A,C) = 5.

BFS from A will return A->C as the shortest path, but for the weighted graph, it is a path of weight 5!!! while the shortest path is of weight 2: A->B->C.
Dijkstra's algorithm will not make this mistake, and return the shortest weighted path.

If your graph is unweighted - BFS is both optimal and complete - and should usually be prefered over dijkstra - both because it is simpler and faster (at least asymptotically speaking).




回答2:


Normally Best First Search algorithms in path finding, searching for path between two given nodes: Source and Sink, but Dijkstra's algorithm finds path between source and all other nodes. So you can't compare them. Also Dijkstra itself is kind of Best First Search (variation of A*) means you can't say it's not Best First Search. Also normal Best First Search Algorithms are using heuristics and they're not guarantee about correctness, Finally in weighted case normally their running time depends on weights, but Dijkstra's algorithm just depend to graph size.




回答3:


BFS is good for finding shortest path from source to a vertex in case where all edges have same weight i.e. to find minimum no of edges from source to a vertex. While Dikjstra holds good for weighted graphs



来源:https://stackoverflow.com/questions/10374357/why-use-dijkstras-algorithm-instead-of-best-cheapest-first-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!