1

I'm trying to understand why Johnson’s algorithm can handle graphs with negative edge weights by using a potential function, while A* cannot, even though both use similar weight adjustments.

Johnson’s Algorithm:

Uses Bellman–Ford to compute exact potentials. Reweights all edges to be nonnegative. Allows Dijkstra’s algorithm to run correctly.

A* Search:

Uses a heuristic h(u) to guide the search. Requires h(u)≤w(u,v)+h(v) for consistency. so if I denote w' as w(u,v)+h(v)-h(u), I know the weight is positive, and I can use dijkstra, but searching in the web it's seems A* cannot handle it. I would glad if someone could help me understand this

miiky123
  • 125
  • 3

2 Answers2

1

Johnson's algorithm can handle negative edge weights because it reweights the graph to eliminate negative weights before using Dijkstra's algorithm for shortest path computation. This reweighting ensures no negative edges remain while preserving the relative shortest path distances.

In contrast, A* cannot handle negative weights because it relies on the assumption that all edge weights are non-negative to maintain a correct and efficient heuristic search. Negative weights would violate this assumption and cause the algorithm to behave unpredictably or fail to guarantee optimality.

1

The reason is because the underlying algorithms, Bellman–Ford and Dijkstra, can/cannot deal with negative weights.

The reason Dijkstra cannot handle negative weights is because it is, in some sense, a greedy algorithm: once a vertex is visited, it is assumed the correct shortest path has been found.

Ainsley H.
  • 17,823
  • 3
  • 43
  • 68