40 likes | 146 Views
Shortest Path Algorithm. l ( v ) - label of the vertex v 1. Set l ( u 0 ) = 0, l ( v ) = for v u 0 , S 0 = { u 0 } and i = 0.
E N D
Shortest Path Algorithm l(v) - label of the vertex v 1. Set l(u0) = 0, l(v) = for v u0, S0 ={u0} and i = 0. 2. For each v not in Si, replace l(v) by min{l(v) , l(ui) + w(ui,v)}. Compute the minimum of the vertices not in Si and let ui+1 denote a vertex for which this minimum is attained. Set Si{ui+1}. 3. If i is one less than the number of vertices in a graph, stop. If i < v -1, replace i by i++ go to step 2.
a f b c e d w(a,b) = 21, w(a,c) = 7, w(a,e) = 6, w(a,f) =5 w(b,c) =16, w(b,d) = 8, w(b,f) = 4, w(c,d) = 3, w(c,e) = 12 w(d,e) = 9, w(d,f) = 14 w(e,f) = 2
4 8 12 16 w(1,2) = 1, w(1,5) = 3, w(2,3) = 2, w(2,5) = 1, w(2,6) = 6, w(2,7) = 2, w(3,4) = 3, w(3,7) = 5, w(3,8) = 1, w(4,8) = 2, w(5,6) = 3, w(5,9) = 2, w(5,10) = 1, w(6,7) = 1, w(6,10) = 1, w(7,8) = 1, w(7,10) = 1, w(7,11) = 3, w(7,12) = 2, w(8,12) = 3, w(9,10) = 2, w(9,13) = 4, w(9,14) = 5, w(10,11) = 2, w(10,14) = 1, w(10,15) = 5, w(11,12) = 2, w(11,15) = 2, w(11,16) = 3, w(12,16) = 1, w(13,14) = 2, w(14,15) = 1, w(15,16) = 2 3 7 11 15 2 6 10 14 1 5 9 13