views:

184

answers:

2

What if the only negative edge costs are coming from the initial node? Will the algorithm still work?

I feel like yes because I can't think of a counter-example, but I'm having trouble proving it. Anyone have a counter-example?

Negative edges are a problem for Dijkstra's because there's no guarantee that the edge you pick produces the shortest path if there is an edge you can pick later that is largely negatively weighted. But if the only negative edges are coming out of the initial node, I don't see the problem.

I'm not looking for an algorithm. I'm looking for some insight into the Dijkstra's.

[EDIT] Sorry! I forgot to add that I'm talking about a directed graph, if that makes a difference.

+5  A: 
Beta
+5  A: 

Counter-example:

Graph G = (V, E), with vertices V = {A, B}, edges E = {(A, B), (B, A)} and weight function w(A, B) = -2, w(B, A) = +1.

There's a negative weight cycle, hence minimum distances are undefined (even using A as initial node).

Sheldon L. Cooper
Wait, I don't understand why this doesn't work.
swiftee
Dijkstra's algorithm will tell you that a minimum weight path from A to B is [A, B], with weight -2. But there are paths from A to B with less weight than that, for example [A, B, A, B] with weight -3.
Sheldon L. Cooper
Ah, I see. Thanks!
swiftee
Marked as the answer because I asked for a counter-example or a proof otherwise.
swiftee