2.2 Dijkstra's Algorithm
2.2 Dijkstra's Algorithm
Vertex X is marked.
Pick up vertex with minimum distance value. The vertex A is picked and marked. The visited
array become [X, A]. Update the distance values of adjacent vertices of A
Adjacent vertices of A are B,M,L. The
distance of B,M,L are updated as 7,9,13.
Pick up vertex with minimum distance value. The vertex B is picked and marked. The visited array
become [X, A, B]. Update the distance values of adjacent vertices of B.
Adjacent vertices of M is V.
The distance of V is updated
as 15.
Pick up vertex with minimum distance value. The vertex N is picked and marked. The visited array
become [X, A, B, M, N]. Update the distance values of adjacent vertices of N.
Pick up vertex with minimum distance value. The vertex C is picked and marked. The visited array
become [X, A, B, M, N, C]. Update the distance values of adjacent vertices of E and O.
Adjacent vertices of Z
is U. The distance of
U is updated as 14.
We repeat the above steps until visit array includes all vertices of the given graph. And, finally we will
get the Shortest Path Tree like this.
From the graph above, it can be seen that the shortest path from X to Y in the Dijkstras Algorithm has
distance values is 26.
From here we can see two paths from X to Y and have the same distance of 26 are:
X ➡ A➡B➡N➡T➡H➡G➡Y (red)
=2+5+3+8+6+1+1 =26
X ➡ A➡B➡N➡Z➡U➡T➡H➡G➡Y (green)
=2+5+3+2+2+4+6+1+1=26