Dijkstra's Algorithm: Exercise

  • Trace Dijkstra's algorithm (shortest path in weighted graphs) by specifying the values in auxiliary data structures.

Exercise Find the weighted shortest path from vertex $3$ to vertex $5$ in the digraph (directed graph) below.

The following parts will guide you through the process.

  1. Fill out the table below with each vertex and its corresponding outgoing vertices.
VertexOutgoing
0
1
2
3
4
5
Solution
VertexOutgoing
01, 2, 4, 5
14, 5
23, 4
32
40, 1, 5
5none
  1. Start with the following default values in Table 1 below (fill out the answers from part-1 in the "Outgoing" column). How would these values change after exploring vertex $3$? Next, fill out Table 2 with your response. What is now the unexplored vertex with the smallest distance from vertex $3$?
Table 1: Default values
VertexOutgoingDistance from 3PreviousExplored
0INFINITYnullno
1INFINITYnullno
2INFINITYnullno
3INFINITYnullno
4INFINITYnullno
5INFINITYnullno
Table 2: After exploring vertex 3
VertexOutgoingDistance from 3PreviousExplored
0
1
2
3
4
5
Solution

Unexplored vertex with the smallest distance: 2

Table 1: Default values
VertexOutgoingDistance from 3PreviousExplored
01, 2, 4, 5INFINITYnullno
14, 5INFINITYnullno
23, 4INFINITYnullno
32INFINITYnullno
40, 1, 5INFINITYnullno
5noneINFINITYnullno
Table 2: After exploring vertex 3
VertexOutgoingDistance from 3PreviousExplored
01, 2, 4, 5INFINITYnullno
14, 5INFINITYnullno
23, 4103no
320nullyes
40, 1, 5INFINITYnullno
5noneINFINITYnullno
  1. How would these values change after exploring vertex $2$? Fill out Table 3 with your response. What is now the unexplored vertex with the smallest distance from vertex $3$?
Table 3: After exploring vertex 2
VertexOutgoingDistance from 3PreviousExplored
0
1
2
3
4
5
Solution

Unexplored vertex with the smallest distance: $4$

Table 3: After exploring vertex 2
VertexOutgoingDistance from 3PreviousExplored
01, 2, 4, 5INFINITYnullno
14, 5INFINITYnullno
23, 4103yes
320nullyes
40, 1, 5222no
5noneINFINITYnullno
  1. How would these values change after exploring vertex $4$? Fill out Table 4 with your response. What is now the unexplored vertex with the smallest distance from vertex $3$?
Table 4: After exploring vertex 4
VertexOutgoingDistance from 3PreviousExplored
0
1
2
3
4
5
Solution

Unexplored vertex with the smallest distance: $0$

Table 4: After exploring vertex 4
VertexOutgoingDistance from 3PreviousExplored
01, 2, 4, 5344no
14, 5524no
23, 4103yes
320nullyes
40, 1, 5222yes
5none504no
  1. How would these values change after exploring vertex $0$? Fill out Table 5 with your response. What is now the unexplored vertex with the smallest distance from vertex $3$?
Table 5: After exploring vertex 0
VertexOutgoingDistance from 3PreviousExplored
0
1
2
3
4
5
Solution

Unexplored vertex with the smallest distance: $1$

Table 5: After exploring vertex 0
VertexOutgoingDistance from 3PreviousExplored
01, 2, 4, 5344yes
14, 5440no
23, 4103yes
320nullyes
40, 1, 5222yes
5none490no
  1. How would these values change after exploring vertex $1$? Fill out Table 6 with your response. What is now the unexplored vertex with the smallest distance from vertex $3$?
Table 6: After exploring vertex 1
VertexOutgoingDistance from 3PreviousExplored
0
1
2
3
4
5
Solution

Unexplored vertex with the smallest distance: $5$

Table 6: After exploring vertex 1
VertexOutgoingDistance from 3PreviousExplored
01, 2, 4, 5344yes
14, 5440yes
23, 4103yes
320nullyes
40, 1, 5222yes
5none490no
  1. How would these values change after exploring vertex $5$? Fill out Table 7 with your response.
Table 7: After exploring vertex 5
VertexOutgoingDistance from 3PreviousExplored
0
1
2
3
4
5
Solution
Table 7: After exploring vertex 5
VertexOutgoingDistance from 3PreviousExplored
01, 2, 4, 5344yes
14, 5440yes
23, 4103yes
320nullyes
40, 1, 5222yes
5none490yes
  1. What is the weighted shortest path from vertex 3 to 5? What is the total distance of this path?
Solution

The weighted shortest path from vertex $3$ to vertex $5$ is:

$$ 3 \implies 2 \implies 4 \implies 0 \implies 5 $$

And the distance is $49$.