What does Bellman-Ford algorithm detects? Negative weight or negative cycle?

前端 未结 2 635
梦谈多话
梦谈多话 2021-02-09 06:33

If we are given a graph, Now from source we are to calculate the shortest path. Now , If an edge has a negative weight , but there is edge to back-edge to get back to that edge

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-09 07:00

    A negative weight cycle is a cycle with weights that sum to a negative number. The Bellman-Ford algorithm propagates correct distance estimates to all nodes in a graph in V-1 steps, unless there is a negative weight cycle. If there is a negative weight cycle, you can go on relaxing its nodes indefinitely. Therefore, the ability to relax an edge after V-1 steps is a test for the presence of a negative weight cycle, as seen in the Wikipedia algorithm. So the Bellman-Ford algorithm tests for negative weight cycles.

提交回复
热议问题