Skip to content
Official PYQ · 2004

GATE CS 2004 Q44 — Shortest Paths (Dijkstra, Bellman-Ford)

Explain with AI

Suppose we run Dijkstra’s single source shortest path algorithm on the following edge-weighted directed graph with vertex PP as the source.

In what order do the nodes get included into the set of vertices for which the shortest path distances are finalized?

Choose one option
View worked solution

Answer: B

Dijkstra's algorithm greedily selects the vertex with the minimum tentative distance that has not yet been finalized. Let d(v)d(v) denote the shortest path estimate to vertex vv.

Starting with source PP (d(P)=0d(P) = 0 and all other distances initialized to ∞\infty):

StepVertex Finalizedd(P)d(P)d(Q)d(Q)d(R)d(R)d(S)d(S)d(T)d(T)d(U)d(U)
1PP01155∞\infty∞\infty∞\infty
2QQ-144∞\infty1010∞\infty
3RR--4∞\infty101066
4UU---9910106
5SS---91010-
6TT----10-

Thus, the order in which the vertices are finalized is P,Q,R,U,S,TP, Q, R, U, S, T.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Shortest Paths (Dijkstra, Bellman-Ford) questions