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

Directed weighted graph with vertices S, A, B, C, D, E, F, G, T. Edges: S to A (4), S to D (7), S to B (3), B to S (3), A to C (1), B to D (4), C to E (1), C to D (3), D to E (1), D to T (3), D to F (5), E to G (2), G to E (2), E to T (4), G to T (3), T to F (5).
Directed weighted graph
Choose one option
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.

  1. Edges and weights (from the figure):
  • From SS: S→AS \to A (4), S→DS \to D (7), S→BS \to B (3)
  • From AA: A→CA \to C (1)
  • From BB: B→SB \to S (3), B→DB \to D (4)
  • From CC: C→EC \to E (1), C→DC \to D (3)
  • From DD: D→ED \to E (1), D→TD \to T (3), D→FD \to F (5)
  • From EE: E→GE \to G (2), E→TE \to T (4)
  • From GG: G→EG \to E (2), G→TG \to T (3)
  • From TT: T→FT \to F (5)
  1. Run Dijkstra from SS, updating a distance only when a strictly shorter path is found:
  • Extract SS (0): d(A)=4d(A) = 4, d(D)=7d(D) = 7, d(B)=3d(B) = 3.
  • Extract BB (3): B→DB \to D gives 3+4=73 + 4 = 7, not strictly less than 77, so DD keeps parent SS.
  • Extract AA (4): d(C)=5d(C) = 5 via AA.
  • Extract CC (5): d(E)=6d(E) = 6 via CC; C→DC \to D gives 8>78 > 7 (no update).
  • Extract EE (6): d(G)=8d(G) = 8 via EE; d(T)=6+4=10d(T) = 6 + 4 = 10 via EE.
  • Extract DD (7): D→ED \to E gives 8>68 > 6; D→TD \to T gives 7+3=107 + 3 = 10, not strictly less than 1010 (no update); d(F)=12d(F) = 12.
  • Extract GG (8): G→TG \to T gives 11>1011 > 10 (no update).
  • Extract TT (10).
  1. The candidate paths SDT (7+37 + 3), SBDT (3+4+33 + 4 + 3) and SACET (4+1+1+44 + 1 + 1 + 4) all have length 1010, while SACDT has length 4+1+3+3=114 + 1 + 3 + 3 = 11. Because TT was first reached through EE and later equal-length paths do not replace it, following parents back from TT gives T←E←C←A←ST \leftarrow E \leftarrow C \leftarrow A \leftarrow S, i.e. SACET.
Final answer

D

Common trap

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.