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

I read about Graph algorithms and I came across these two algorithms.

I searched a lot about this, but did not get a satisfactory answer!

I have doubts, what is the difference between Dijkstra's algorithm and BFS when finding the shortest path?

when using BFS to find the shortest path in a graph, what we do is

We find all connected vertices, add them to the queue and maintain the distance from the source to this vertex. Now, if we find a path from the source to this peak with an even smaller distance, then we will update it!

This is the same thing that we do in Dijkstra's algorithm! then what is the difference between dijkstra and bfs? And then why are the time complexity of these algorithms different from each other?

If anyone can explain this with pseudo code, then I will be very grateful!

I know something is missing! Please help!

+24
algorithm graph
Aug 22 '14 at
source share
2 answers

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

Dijkstra's algorithm is a conceptually broad search that takes into account edge costs.

The process of studying the graph in both cases is structurally the same.

+53
Aug 22 '14 at 2:52
source share
— -

Blockquote when using BFS to find the shortest path in the graph of what we do. We find all the connected vertices, add them to the queue, and also maintain the distance from the source to this vertex. Now, if we find a path from the source to this peak with an even smaller distance, then we will update it!

We do not maintain distance in BFS. This is for node detection. Therefore, we put them in a common queue and pop up. unlike Dijikstra, where we put the cumulative weight of the node (after relaxation) in the priority queue and exit at the minimum distance.

Thus, the BFS will work as a dijikstra in a graph of equal weight, because.

complexity varies due to the use of a simple queue and priority queue.

+1
May 03 '17 at 6:19 a.m. 06:19
source share



All Articles