Algorithms and Data Structures · Senior · Question 1 of 75

Why does Dijkstra's algorithm give wrong results with negative edge weights?

Explanation

Dijkstra assumes that once the closest vertex is taken from the queue, no later path can be shorter. A negative edge breaks that assumption. Bellman-Ford handles negative weights in O(V × E) and also detects negative cycles.

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 1

Test yourself

Take the Algorithms and Data Structures · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz