0

Suppose we have a digraph containing both positively and negatively weighted edges.

I understand that the shortest-path solution is the Bellman-Ford algorithm.

My question is: why can we not just add some large value N to all the edge costs so that there are no longer negative edges, then use the far more efficient Dijkstra algorithm?

Dylan Fouche
  • 91
  • 2
  • 8

1 Answers1

1

Adding a constant to each edge length is not monotone on path lengths, even for pathes between the same two nodes (as paths may differ in their number of edges). Consider the graph with edges ab, bc, and ac of weight -1. Adding N=2 switches the shortest path from a to c from ab,bc to ac.

asp
  • 172
  • 5