Home > other >  add cycles with negative weights check in Floyd-Warshall
add cycles with negative weights check in Floyd-Warshall

Time:06-25

This is the pseudo-code for the Floyd-Warshall algorithm for shortest paths detection: enter image description here

I was wondering if it would be possible to add a check that will test if there are no cycles with negative weights?

I think it is possible, but I do not know how to check.

CodePudding user response:

Take the sum of all negative weights in the graph.

You have a negative cycle if and only if you find a path to a weight that is below that minimum.

  • Related