According to this page, Dijkstra's algorithm is just BFS with a priority queue. Is it really that simple? I think not.
migrated from cstheory.stackexchange.com Feb 24 '13 at 8:51
This question came from our site for theoretical computer scientists and researchers in related fields.
You can implement Dijkstra's algorithm as BFS with a priority queue (though it's not the only implementation).
Dijkstra's algorithm relies on the property that the shortest path from $s$ to $t$ is also the shortest path to any of the vertices along the path. This is exactly what BFS does.
Or in another perspective: how would Dijkstra's algorithm behave if all the weights were 1? Exactly like BFS.
Here is an idea from the book "Algorithms (Section 4.4)" by Dasgupta et al:
For any edge $e = (u,v)$ of $E$ (with weight $l_e$), replace it by $l_e$ edges of length $1$, by adding $l_e - 1$ dummy nodes between $u$ and $v$.
As a result, the edges of the result graph $G'$ all have unit length. Therefore, we can compute distances in $G$ by running BFS on $G'$.
BFS on $G'$ can be really slow if some $l_e$ are big because it wastes too much time on computing distances to those dummy nodes that we don't care about at all. The Dijkstra algorithm avoids this by setting estimated distances for nodes and relaxing them whenever possible.
It behaves exactly the same as BFS does. We elaborate this from two major points.