Johnson's algorithm: Difference between revisions

Content deleted Content added
m Algorithm description: fix math italics
Line 27:
[[File:Johnson's algorithm.svg|540px|center]]
 
The graph on the left of the illustration has two negative edges, but no negative cycles. At the center is shown the new vertex {{mathmvar|''q''}}, a shortest path tree as computed by the Bellman–Ford algorithm with {{mathmvar|''q''}} as starting vertex, and the values {{math|''h''(''v'')}} computed at each other node as the length of the shortest path from {{mathmvar|''q''}} to that node. Note that these values are all non-positive, because {{mathmvar|''q''}} has a length-zero edge to each vertex and the shortest path can be no longer than that edge. On the right is shown the reweighted graph, formed by replacing each edge weight {{mathtmath|''w(u,v)''}} by {{math|''w''(''u'',''v)'') + ''h''(''u)'') − ''h''(''v)'')}}. In this reweighted graph, all edge weights are non-negative, but the shortest path between any two nodes uses the same sequence of edges as the shortest path between the same two nodes in the original graph. The algorithm concludes by applying Dijkstra's algorithm to each of the four starting nodes in the reweighted graph.
 
==Correctness==