Johnson's algorithm: Difference between revisions

Content deleted Content added
Suurballe's algorithm; {{math}}
Line 13:
#Finally, {{math|''q''}} is removed, and [[Dijkstra's algorithm]] is used to find the shortest paths from each node {{math|''s''}} to every other vertex in the reweighted graph.
 
In the reweighted graph, all paths between a pair {{math|''s''}} and {{math|''t''}} of nodes have the same quantity {{math|''h(s)'' − ''h(t)''}} added to them, so a path that is shortest in the original graph remains shortest in the modified graph and vice versa. HoweverIf the graph did not contain a negative cycle, then due to the way the values {{math|''h(v)''}} were computed, all modified edge lengths are non-negative, ensuring the optimality of the paths found by Dijkstra's algorithm. The distances in the original graph may be calculated from the distances calculated by Dijkstra's algorithm in the reweighted graph by reversing the reweighting transformation.
 
==Analysis==