Algorithms and Data Structures · Senior · Question 2 of 75

What extra capability does Bellman-Ford have compared with Dijkstra?

Explanation

It relaxes all edges V - 1 times; if a V-th pass still improves a distance, there's a negative cycle. The price is O(V × E), much slower than Dijkstra's O((V + E) log V).

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 2

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