Johnson's AlgorithmThe problem is to find the shortest path between every pair of vertices in a given weighted directed graph and weight may be negative. Using Johnson's Algorithm, we can find all pairs shortest path in O (V^{2} log ? V+VE ) time. Johnson's Algorithm uses both Dijkstra's Algorithm and BellmanFord Algorithm. Johnson's Algorithm uses the technique of "reweighting." If all edge weights w in a graph G = (V, E) are nonnegative, we can find the shortest paths between all pairs of vertices by running Dijkstra's Algorithm once from each vertex. If G has negative  weight edges, we compute a new  set of non  negative edge weights that allows us to use the same method. The new set of edges weight w must satisfy two essential properties:
Given a weighted, directed graph G = (V, E) with weight function w: E→R and let h: v→R be any function mapping vertices to a real number. For each edge (u, v) ∈ E define Where h (u) = label of u JOHNSON (G) 1. Compute G' where V [G'] = V[G] ∪ {S} and E [G'] = E [G] ∪ {(s, v): v ∈ V [G] } 2. If BELLMANFORD (G',w, s) = FALSE then "input graph contains a negative weight cycle" else for each vertex v ∈ V [G'] do h (v) ← δ(s, v) Computed by BellmanFord algorithm for each edge (u, v) ∈ E[G'] do w (u, v) ← w (u, v) + h (u)  h (v) for each edge u ∈ V [G] do run DIJKSTRA (G, w, u) to compute δ (u, v) for all v ∈ V [G] for each vertex v ∈ V [G] do d_{uv}← δ (u, v) + h (v)  h (u) Return D. Example: Step1: Take any source vertex's' outside the graph and make distance from's' to every vertex '0'. Step2: Apply BellmanFord Algorithm and calculate minimum weight on each vertex. Step3: w (a, b) = w (a, b) + h (a)  h (b) w (b, a) = w (b, a) + h (b)  h (a) Step 4: Now all edge weights are positive and now we can apply Dijkstra's Algorithm on each vertex and make a matrix corresponds to each vertex in a graph Case 1: 'a' as a source vertex Case 2: 'b' as a source vertex Case 3: 'c' as a source vertex Case4:'d' as source vertex Step5: d_{uv} ← δ (u, v) + h (v)  h (u)
Next Topic#
