Data Structures & AlgorithmsVery hardProduct-company placement

Dijkstra's algorithm runs from A on the directed graph A→D (15), B→A (1), B→C (13), B→F (10), C→D (6), C→F (11), D→B (2), D→E (14), D→F (13), E→A (11), E→B (7), F→A (2) (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. 3 times, final 27
  2. B. 2 times, final 27
  3. C. 1 time, final 27
  4. D. 2 times, final 28

Correct answer: B. 2 times, final 27

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic