Consider the directed graph shown in the figure below. There are multiple…

2012

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.

  1. A.

    SDT

  2. B.

    SBDT

  3. C.

    SACDT

  4. D.

    SACET

Attempted by 148 students.

Show answer & explanation

Correct answer: D

Answer: The path reported by Dijkstra’s algorithm is S → A → C → E → T.

Key idea: Dijkstra fixes vertices in increasing order of distance; when a candidate distance equals the current distance, we do not update (updates occur only on strictly shorter paths).

  1. Initial relaxations from S: set tentative distances (examples) — dist(B)=3, dist(A)=4, dist(D)=7; other vertices are ∞.

  2. Extract the smallest tentative vertex B (dist=3) and relax edges from B. Relaxing B → D gives candidate dist(D)=3+4=7, which equals the current dist(D)=7, so no update is made (strict-update rule).

  3. Extract A next (dist=4). Relaxing A → C sets dist(C)=5.

  4. Extract C (dist=5). Relaxing C → E sets dist(E)=6. Relaxing C → D gives candidate dist(D)=8, which is worse than current 7, so no update.

  5. Extract E (dist=6). Relaxing E → T sets dist(T)=10 and records predecessor of T as E.

  6. Later extract D (dist=7). Relaxing D → T yields candidate dist(T)=7+3=10, which equals the existing dist(T). Because updates require a strictly shorter path, the predecessor of T is not changed.

  7. Therefore the final predecessor chain to T is T ← E ← C ← A ← S, giving the reported path S → A → C → E → T.

Remarks: There are multiple shortest paths of equal total cost (for example S → D → T and S → B → D → T also have the same total cost), but the tie-breaking behavior and the strict-update rule determine which shortest path is actually reported by Dijkstra in this run.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir