Why can't a directed weighted graph contain cycles of negative weight, if we want to determine the shortest path between two nodes of that graph?
No negative cycles when determining path between two nodes
132 views Asked by Drago At
4
There are 4 answers
0
On
Because if it does, the shortest path can be -inf.
Imagine this example, you want to compute the shortest path between A and D. Probably you want it to be A - B - D, 6 steps. But you can loop the cycle B - C - B as many times as you want. Then, the shortest path is A - B - C - B - C - ... - B - C - B - D.

Because a negative cycle would affect the path-weight in the following-way:
First attempt of finding a path:
Now let's enter the loop:
Well that's cheaper by two, but we can do better:
The obvious problem: with every run through the loop the path gets cheaper and we wind up with an endless loop as shortest path.
But this doesn't apply to all path-finding algorithms. For example the Bellman-Ford-algorithm is capable of handling negative edges, with the cost of being less efficient.