Why do all paired shortest path algorithms work with negative weights?

Recently, I have been studying the shortest path algorithms for all pairs, such as the Floyd-Warsall and Johnson algorithm, and I noticed that these algorithms give the correct solutions even if the graph contains negative weight boundaries (but not negative weight cycles), for comparison, Dijkstra's algorithm (which is the shortest path with a single source) does not work for negative weight edges. What does paired-pair algorithm algorithms do with minimal weights?

+4
source share
2 answers

Floyd Warshall works with minimal edge algorithm algorithms because the correctness of the algorithm does not depend on the weight of the edge, which is non-negative, while the correctness of Dijkstra's algorithm is based on this fact.

The correctness of Dijkstra's algorithm:

We have 2 sets of vertices at any step of the algorithm. Set A consists of vertices on which we calculated the shortest paths. Set B consists of the remaining vertices.

Inductive hypothesis . At each step, we will assume that all previous iterations are correct.

Inductive step . When we add the vertex V to the set A and specify the distance to dist [V], we must prove that this distance is optimal. If this is not optimal, then there must be some other way to the vertex V, which has a shorter length.

, X B.

, dist[V] <= dist[X], V dist [V], .

: S T U . , S T

min (shortest_path ( S U) + shortest_path ( U T)) U .

, , , . , .

+4

Dijkstra Algorithm , (), v S, d [v] .

Q ​​ S . , , .

, .

0

Source: https://habr.com/ru/post/1535224/


All Articles