Johnson's Algorithm For All-Pairs Shortest Paths
Johnson's Algorithm For All-Pairs Shortest Paths
Dist s a b c d
K=1 0 0 0 0 0
K=2 0 -1 -3 0 0
K=3 0 -1 -4 0 0
K=4 0 -1 -4 -1 0
h(a)=-1
h(b)=-4
h(c)=-1
h(d)=0
s
Step3: w (a, b) = w (a, b) + h (a) - h (b)
= -3 + (-1) - (-4)
=0
w (b, a) = w (b, a) + h (b) - h (a)
= 5 + (-4) - (-1)
=2
w (b, c) = w (b, c) + h (b) - h (c)
w (b, c) = 3 + (-4) - (-1)
=0
w (c, a) = w (c, a) + h (c) - h (a)
w (c, a) = 1 + (-1) - (-1)
=1
w (d, c) = w (d, c) + h (d) - h (c)
w (d, c) = 4 + 0 - (-1)
=5
w (d, a) = w (d, a) + h (d) - h (a)
w (d, a) = -1 + 0 - (-1)
=0
w (a, d) = w (a, d) + h (a) - h (d)
w (a, d) = 2 + (-1) - 0 = 1
a b c d
0 0 0 1
δ (u, v)
• In the next step using this table re- calculation of weights has to be done
using duv ← δ (u, v) + h (v) - h (u)
‘h’ values need to be taken from step-2
duv ← δ (u, v) + h (v) - h (u)
d (a, a) = 0 + (-1) - (-1) = 0
d (a, b) = 0 + (-4) - (-1) = -3
d (a, c) = 0 + (-1) - (-1) = 0
d (a, d) = 1 + (0) - (-1) = 2