GATE Computer ScienceHardGATE CS (PYQ pattern)

Dijkstra's algorithm (never re-inserting or re-opening a vertex once it has been extracted) is run from S on a directed graph with edges S→A 4, S→B 5, A→C 3, B→A −3, B→D 6, C→D −2, C→T 8, D→T 3. What distance label does it finally assign to T?

  1. A. 6
  2. B. 8
  3. C. 7
  4. D. 5

Correct answer: B. 8

Dijkstra extracts S, A (4), B (5), C (7), D (5, improved from 11 through C) and finally T with 8. It never reopens A after the negative edge B→A, so A, C, D and T keep labels that are too large. The true shortest distance is 6 via S→B→A→C→D→T (5 − 3 + 3 − 2 + 3).

More Algorithms questions

Exams that ask this topic