Question
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 is updated only when a strictly shorter path to is discovered.
Official answer and solution
- Official answer
- D
- From
- Official GATE 2012 answer key
Solution
Trace Dijkstra's algorithm from S, applying the strict-update rule, and follow the parent pointers back from T.
- Edges and weights (from the figure):
- From : (4), (7), (3)
- From : (1)
- From : (3), (4)
- From : (1), (3)
- From : (1), (3), (5)
- From : (2), (4)
- From : (2), (3)
- From : (5)
- Run Dijkstra from , updating a distance only when a strictly shorter path is found:
- Extract (0): , , .
- Extract (3): gives , not strictly less than , so keeps parent .
- Extract (4): via .
- Extract (5): via ; gives (no update).
- Extract (6): via ; via .
- Extract (7): gives ; gives , not strictly less than (no update); .
- Extract (8): gives (no update).
- Extract (10).
- The candidate paths SDT (), SBDT () and SACET () all have length , while SACDT has length . Because was first reached through and later equal-length paths do not replace it, following parents back from gives , i.e. SACET.
D
Choosing SDT or SBDT: they are also shortest (length 10), but T's distance is first set to 10 via E, and the strict-update rule never replaces it.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2012 Computer Science and Information Technology (CS)
- Question
- 40 of 65, printed as CS Q.40
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.