What is difference between BFS and Dijkstra's algorithms when looking for shortest path?

后端 未结 3 910
醉酒成梦
醉酒成梦 2020-12-12 16:37

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!

I have a do

相关标签:
3条回答
  • 2020-12-12 16:47

    With SPFA algorithm, you can get shortest path with normal queue in weighted edge graph.

    It is variant of bellman-ford algorithm, and it can also handle negative weights.

    But on the down side, it has worse time complexity over Dijkstra's

    0 讨论(0)
  • 2020-12-12 17:06

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

    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.

    0 讨论(0)
  • 2020-12-12 17:09

    Blockquote 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!

    We do not maintain a distance in BFS. It is for discovery of nodes. So we put them in a general queue and pop them. unlike in Dijikstra where we put accumulative weight of node (after relaxation) in a priority queue and pop the min distance.

    So BFS would work like dijikstra in equal weight graph because.

    complexity varies because of the use of simple queue and priority queue.

    0 讨论(0)
提交回复
热议问题