Dijktra algorithm vs breath first search for shortest path in graph

杀马特。学长 韩版系。学妹 提交于 2019-12-14 03:28:08

问题


I need some clarifications and inputts regarding Dijktra's algorithm vs breath first search in directed graphs, if these are correct.

Dijktra's algorithm finds the shortest path from Node A to Node F in a weighted graph regardless of if there is a cycle or not (as long as there are no negative weights)

but for that, All paths from A to all other Nodes in the graph are calculated and we grab the path fromAtoFby reversing the sequences of nodes inprev`.

BFS: finds the shortest path from Node A to Node F in a non-weighted graph, but if fails if a cycle detected.

however, BFS just calculates the path from Node A to Node F and not necessarily all path from Node A. if Node F is reached early, it just returns the path.


回答1:


Dijkstra doesn't search all nodes of the graph. When it has found a way from A to F and is sure there is no shorter one (because the outer border of the already visited nodes is farther away), it stops. This is possible without negative weights.

So to answer your question "if these are correct": They are not.




回答2:


Those algorithms are quite different in terms of their execution.

BFS is a kind of brute-force algorithm that follows a "static execution pattern" Dijkstra on the other hand is more dynamic and continues its search always at the point with the lowest cost.

The purpose of dijkstra is to find the shortest path. So if you are looking for the shortest path use dijkstra.



来源:https://stackoverflow.com/questions/20060357/dijktra-algorithm-vs-breath-first-search-for-shortest-path-in-graph

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