Data Structures & AlgorithmsVery hardGATE CS

Dijkstra's algorithm runs from A on the directed graph A→C (4), A→D (15), B→A (2), B→C (13), C→D (8), C→E (7), C→F (2), D→B (12), E→B (7), F→A (13), F→D (8), F→E (2) (relaxations into already-finalised vertices are skipped). How many times is dist[D] lowered (counting the first change from ∞), and what is its final value?

  1. A. 3 times, final 12
  2. B. 2 times, final 12
  3. C. 1 time, final 12
  4. D. 2 times, final 15

Correct answer: B. 2 times, final 12

dist[D] drops only when a newly finalised in-neighbour gives a strictly shorter route; tracing the finalisation order A C F E D B gives 2 decreases ending at 12. It is not simply the in-degree (3).

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic