Consider the directed graph shown in the figure below. There are multi...
Let d[v] represent the shortest path distance computed from ‘S’
Initially d[S]=0, d[A] = ∞, d[B] = ∞.− − − −,d[T] = ∞
And let P[v] represent the predecessor of v in the shortest path from ‘S’ to ‘v’ and let P[v]=-1
denote that currently predecessor of ‘v’ has not been computed
→ Let Q be the set of vertices for which shortest path distance has not been computed
→ Let W be the set of vertices for which shortest path distance has not been computed
→ So initially, Q = {S,A,B,C,D,E,F,G,T},W = f
We will use the following procedure
Repeat until Q is empty
{
1 u = choose a vertex from Q with minimum d[u] value
2. Q = Q − u
3. update all the adjacent vertices of u
4. W = W U{u}
}
d[S] = 0, d[A] = ∞, d[B] = ∞ ,………, d[T] = ∞
Step 1 : u = S
Step 2 : Q ={A,B,C,D,E,F,G,T}
Step 3: final values after adjustment
d[S] = 0,d[A] = 4, d[B] = 3,d[C] = ∞,d[D] = 7,d[E] = ∞ − −−,d[T] = ∞
P[A] = S, P[B] = S,P[C] = −1,P[D] = S,P[E] = −1− −−,P[T] = −1
Step 4 : W={S}
Iteration 2:
Step 1: u= B
Step 2 :Q ={A,C,D,E,F,G,T}
step 3: final values after adjustment
d[S] = 0,d[A] = 4, d[B] = 3,d[C] = ∞,d[D] = 7,d[E] = ∞ − −−,d[T] = ∞
P[A] = S, P[B] = S,P[C] = −1,P[D] = S,P[E] = −1− −−,P[T] = −1
Step 4 : W={S,B}
Iteration 3:
Step 1: u= A
Step 2 :Q ={C,D,E,F,G,T}
step 3: final values after adjustment
d[S] = 0,d[A] = 4, d[B] = 3,d[C] = 5,d[D] = 7,d[E] = ∞ − −−,d[T] = ∞
P[A] = S, P[B] = S,P[C] = A,P[D] = S,P[E] = −1− −−,P[T] = −1
Step 4 : W={S,B,A}
Iteration 4:
Step 1: u= A
Step 2 :Q ={D,E,F,G,T}
step 3: final values after adjustment
d[S] = 0,d[A] = 4, d[B] = 3,d[C] = 5,d[D] = 7,d[E] = 6 − −−,d[T] = ∞
P[A] = S, P[B] = S,P[C] = A,P[D] = S,P[E] = −1− −−,P[T] = −1
Step 4 : W={S,B,A,C}
Iteration 5:
Step 1: u= E
Step 2 :Q ={D,F,G,T}
step 3: final values after adjustment
d[S] = 0,d[A] = 4, d[B] = 3,d[C] = 5,d[D] = 7,d[E] = 6,d[F] = ∞,d[G] = 8,d[T] = 10
P[A] = S, P[B] = S,P[C] = A,,P[D] = S,P[E] =C, P[F]= −1, P[G]=E, P[T] = E
Step 4 : W={S,B,A,C,E}
After iteration 5, we can observe that P[T]=E , P[E]=C , P[C]=A , P[A]=S,
So the shortest path from S to T is SACET