Consider the directed graph shown in the figure below. There are multiple shortest paths between vertices S and T. Which one will be reported by Dijkstra’s shortest path algorithm? Assume that, in any iteration, the shortest path to a vertex v is updated only when a strictly shorter path to v is discovered.
Consider the directed graph shown in the figure below. There are multiple shortest paths between vertices S and T. Which one will be reported by Dijkstra’s shortest path algorithm? Assume that, in any iteration, the shortest path to a vertex v is updated only when a strictly shorter path to v is discovered. Correct Answer SACET
The correct answer is “option 4”.
CONCEPT:
Dijkstra’s algorithm is an algorithm used for finding the shortest paths between nodes or vertices in a graph.
This algorithm is basically used to find the shortest path from a starting node to a target node in a weighted graph.
This algorithm creates a tree of the shortest path from a vertex to other nodes in the graph.
This algorithm assigns initial distance values & will try to improve step by step.
Dijkstra’s algorithm works as follows:
1. It initializes distances according to the algorithm.
2. Pick a node and calculate the distance to adjacent nodes.
3. Pick the next node with the smallest distance & repeat distance calculations.
4. Find the result of the shortest-path tree.
CALCULATION:
|
|
S |
A |
C |
E |
G |
D |
B |
F |
T |
|
|
S |
0 |
∞ |
∞ |
∞ |
∞ |
∞ |
∞ |
∞ |
∞ |
|
|
SB |
0 |
4 |
∞ |
∞ |
∞ |
7 |
3 |
∞ |
∞ |
SELECT B |
|
SBA |
0 |
4 |
∞ |
∞ |
∞ |
7 |
3 |
∞ |
∞ |
SELECT A |
|
SBAC |
0 |
4 |
5 |
∞ |
∞ |
7 |
3 |
∞ |
∞ |
SELECT C |
|
SBACE |
0 |
4 |
5 |
6 |
∞ |
7 |
3 |
∞ |
∞ |
SELECT E |
|
SBACED |
0 |
4 |
5 |
6 |
8 |
7 |
3 |
∞ |
10 |
SELECT D |
|
SBACEDT |
0 |
4 |
5 |
6 |
8 |
7 |
3 |
12 |
10 |
SELECT T |
The shortest-path tree is:
[ alt="F1 Raju S 19.5.21 Pallavi D10" src="//storage.googleapis.com/tb-img/production/21/05/F1_Raju%20S_19.5.21_Pallavi_D10.png" style="width: 383px; height: 145px;">
Hence, the shortest path from S to T is S → A → C → E → T.