Dijkstra 算法在寻找最短路径方面比 A* 算法更好吗?
Dijkstra 算法在寻找最短路径方面比 A* 算法更好吗?
How is Dijkstra algorithm better tham A* algorithm for finding shortest path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它并不擅长寻找最短路径。只要您对 A* 有一个可接受的启发式算法,它就会比 Dijkstra 更快地找到短路路径。
正如 Mehrad 在评论中指出的那样,如果你给它一个返回 0 的启发式函数,A* 就会降级为 Dijktras。
A* 的维基百科文章 有大量关于所有这些的好信息。
It is not better at finding the shortest path. As long as you have an admissible heuristic for A* it will find the shorted path quicker than Dijkstra's would.
And as Mehrad pointed out in the comments, A* degrades into Dijktras if you give it a heuristic function that returns 0.
The wikipedia article for A* has a ton of good information on all of this.
如果您想找到从给定源节点到图中所有节点的最短路径,Dijkstra 比 A* 更好,因为如果您不在特定目标处停止,Dijkstra 无论如何都会覆盖整个图。与简单的 Dijkstra A* 相比,A* 是一种面向目标的算法,因此需要知道源节点和目标节点。如果您想使用 A* 算法用 N 个节点覆盖整个图,您基本上必须从源节点运行该算法 N 次。
Dijkstra 也可能更适合查找从源节点到图形的许多目标的最短路径。根据目标的位置(尤其是距源的距离)、目标的数量 M、图表的大小、A* 启发式的质量,将会存在一些盈亏平衡点,其中运行 Dijkstra 的性能比运行更好或更低M 倍 A* 算法。
编辑:受到 Matthew 正确批评评论的启发,我稍微改了一下并添加了注释:
If you want to find the shortest paths from a given source node to all nodes in a graph Dijkstra is better than A* since Dijkstra covers the whole graph anyway if you don't stop at a specific target. In contrast to simple Dijkstra A* is a goal-oriented algorithms and therefore needs to know both source and target node. If you wanted to cover the whole graph with N nodes with an A* algorithm you basically have to run the algorithm N times from the source node.
Dijkstra might also be better for finding the shortest paths from a source node to many targets of the graph. Depending on the location of the targets (especially distance from the source), number of targets M, size of the graph, quality of the A* heuristic there will be some break-even point where running one Dijkstra is better or less performant than running M times the A* algorithm.
Edit: Inspired by Matthew's correct critical comment I rephrase a bit and add remarks: