GateAI
Shortest Paths

GATE CSE 2012 · Q40

MCQ2 marksHard

Time

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 vv is updated only when a strictly shorter path to vv is discovered.

GATE CSE 2012 Q40 diagram

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: D) SACET

Shortest Paths

Let us trace Dijkstra's algorithm step by step starting from source SS:

  1. Initialization:

    • Distances: d(S)=0d(S)=0, all others ∞\infty.

  2. Extract SS (d=0d=0):

    • Relax edges from SS:

      • d(A)=0+4=4d(A) = 0 + 4 = 4, parent(A)=S\text{parent}(A) = S

      • d(B)=0+3=3d(B) = 0 + 3 = 3, parent(B)=S\text{parent}(B) = S

      • d(D)=0+7=7d(D) = 0 + 7 = 7, parent(D)=S\text{parent}(D) = S

  3. Extract BB (d=3d=3):

    • Relax edge (B,D)(B, D) with weight 4: d(D)=min⁡(7,3+4)=7d(D) = \min(7, 3+4) = 7. Since 77 is not strictly shorter than 77, distance and parent of DD are not updated.

  4. Extract AA (d=4d=4):

    • Relax edge (A,C)(A, C) with weight 1: d(C)=4+1=5d(C) = 4 + 1 = 5, parent(C)=A\text{parent}(C) = A.

  5. Extract CC (d=5d=5):

    • Relax edge (C,D)(C, D) with weight 3: 5+3=8>75+3 = 8 > 7 (no update).

    • Relax edge (C,E)(C, E) with weight 1: d(E)=5+1=6d(E) = 5 + 1 = 6, parent(E)=C\text{parent}(E) = C.

  6. Extract EE (d=6d=6):

    • Relax (E,D)(E, D) with weight 1: 6+1=76 + 1 = 7 (not strictly shorter, no update to DD).

    • Relax (E,G)(E, G) with weight 2: d(G)=6+2=8d(G) = 6 + 2 = 8, parent(G)=E\text{parent}(G) = E.

    • Relax (E,T)(E, T) with weight 4: d(T)=6+4=10d(T) = 6 + 4 = 10, parent(T)=E\text{parent}(T) = E.

  7. Extract DD (d=7d=7):

    • Relax (D,T)(D, T) with weight 3: 7+3=107 + 3 = 10 (not strictly shorter than 1010, no update to TT).

    • Relax (D,F)(D, F) with weight 5: d(F)=7+5=12d(F) = 7 + 5 = 12, parent(F)=D\text{parent}(F) = D.

  8. Extract GG (d=8d=8):

    • Relax (G,T)(G, T) with weight 3: 8+3=11>108 + 3 = 11 > 10 (no update).

  9. When TT is reached with distance 10, the parent pointers traced back are:

    T←E←C←A←ST \leftarrow E \leftarrow C \leftarrow A \leftarrow S

Thus, the path found is SACET.

Therefore, (D) is the correct option.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Shortest Paths previous year question is Q40 of the GATE CSE 2012 paper. Find more GATE CSE PYQs on Shortest Paths in Algorithms, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 4 related Shortest Paths PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Shortest Paths in GATE CSE

Shortest Paths has 4 GATE CSE PYQs across 4 papers from 2012 to 2026. 3 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2012.

How GATE tests Shortest Paths

More from GATE CSE 2012

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2012 · Q40 · MCQ

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.

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.