Data Structures & AlgorithmsVery hardGATE CS

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

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

Correct answer: A. 2 times, final 13

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic