문제

I am looking at the Floyd-Warshall algorithm.

let dist be a |V| × |V| array of minimum distances initialized to ∞ (infinity)

// part 1 
for each vertex v
   dist[v][v] ← 0

// part 2
for each edge (u,v)
   dist[u][v] ← w(u,v)  // the weight of the edge (u,v)

// part 3
for k from 1 to |V|
   for i from 1 to |V|
      for j from 1 to |V|
         if dist[i][k] + dist[k][j] < dist[i][j] then
            dist[i][j] ← dist[i][k] + dist[k][j]

In the page, it says the Floyd–Warshall algorithm assumes that there are no negative cycles. So my question is what will happen if the entry graph hides negative circle. Will the output dist represents another graph hiding negative circle? Does not part 1 invalid this?

도움이 되었습니까?

해결책

Floyd-Warshall algorithm is for find the shortest path. If negative circle exist, there is no shortest path(you can find a infinitely small(negative) path).

If negative circle exists then what will happen? I will say the output of Floyd means nothing, that is to say, that algorithm doesn't work(since there is no shortest path, how it can work?).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top