Data Structures & AlgorithmsVery hardProduct-company placement

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

Correct answer: D. 3 times, final 7

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic