寻找最短路径时,是BFS和Dijkstra的算法有什么区别?最短、有什么区别、算法、路径

2023-09-11 05:45:35 作者:资深老可爱

我在阅​​读有关图形算法,我碰到这两种算法。

I was reading about Graph algorithms and I came across these two algorithms.

我搜索了很多关于这一点,但没有得到任何满意的答复!

I searched a lot about this but didn't get any satisfactory answer!

我有一个疑惑,什么是在寻找最短路径?Dijkstra算法和BFS之间的差异

I have a doubt that what is the difference between Dijkstra's algorithm and BFS while looking for shortest path?

在使用BFS寻找一个图的最短路径是什么,我们要做的就是

while using BFS for finding shortest path in a graph what we do is

我们发现所有连接的顶点,将其添加到队列中,同时保持距离 从源头到顶点。现在,如果我们发现从源路径顶点与仍不足的距离,然后我们更新了!

We discover all the connected vertices, add them in the queue and also maintain the distance from source to that vertex. Now if we find a path from source to that vertex with still less distance then we update it!

这正是我们在做的Dijkstra算法同样的事情!那么什么是之间Dijkstra的和BFS的区别?然后,为什么这些算法的时间复杂度如此不同?

This is exactly the same thing we do in Dijkstra's algorithm! then what is the difference between Dijkstra's and BFS? And then why are the time complexities of these algorithms so different?

如果任何人都可以使用的伪code的帮助解释它,然后我会 非常感谢!

If anyone can explain it with the help of a pseudo code then I will be very grateful!

我知道我失去了一些东西!请帮忙!

I know I am missing something! Please help!

推荐答案

广度优先搜索就是Dijkstra算法与等于1的所有边的权重。

Breadth-first search is just Dijkstra's algorithm with all edge weights equal to 1.

Dijkstra算法在概念上是一个尊重边缘成本广度优先搜索。

Dijkstra's algorithm is conceptually breadth-first search that respects edge costs.

的方法,为探索该图在结构在两种情况下是相同的。

The process for exploring the graph is structurally the same in both cases.