0

Let's say Dijkstra is run from a random vertex and it meets a negative-weight cycle on the path. We can loop around the cycle to make the cost as small as possible, but Dijkstra's invariant is not to "re-visit" the visited nodes, so I suppose there won't be an infinite loop and Dijkstra would terminate?

Mariska
  • 1,913
  • 5
  • 26
  • 43

1 Answers1

0

The problem isn't that Dijkstra's algorithm wouldn't terminate, it's that Dijkstra's algorithm doesn't work on graphs with negative weights at all. See this answer for an explanation of why.

Community
  • 1
  • 1
Xymostech
  • 9,710
  • 3
  • 34
  • 44