Take the 2-minute tour ×
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It's 100% free, no registration required.

According to this page, Dijkstra's algorithm is just BFS with a priority queue. Is it really that simple? I think not.

share|improve this question

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.

Why do you think that? –  Raphael Feb 24 '13 at 16:18
@Raphael Because it seems too simple, and it is: I studied it again and I see now it doesn't keep track of the distance between nodes, so it's really a BFS, not Dijkstra. –  Barry Fruitman Feb 24 '13 at 18:21
Well, Dijkstra does change the values the queue is "sorted" with (often called "relaxation"); if you forbid that, it's not the same, true. –  Raphael Feb 24 '13 at 23:15

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.