Skip to main content
Tweeted twitter.com/#!/StackCompSci/status/217974768522108929
edited tags
Link
Kaveh
  • 22.5k
  • 4
  • 52
  • 112
Post Migrated Here from stackoverflow.com (revisions)
Source Link
user1422
user1422

Using Dijkstra's algorithm with negative edges?

Most books explain the reason the algorithm doesn't work with negative edges as nodes are deleted from the priority queue after the node is arrived at since the algorithm assumes the shortest distance has been found. However since negative edges can reduce the distance, a future shorter distance might be found; but since the node is deleted it cannot be updated.

Wouldn't an obvious solution to this be to not delete the node? Why not keep the node in the queue, so if a future shorter distance is found, it can be updated? If I am misunderstanding the problem, what is preventing the algorithm from being used with negative edges?