Data Structures & AlgorithmsHardProduct-company MCQ pattern

Directed edges: A→B (2), A→C (5), C→B (−4), B→D (1). Dijkstra's algorithm, which finalises each vertex once when it is removed from the priority queue, is run from A. What distance does it report for D, and what is the true shortest distance?

  1. A. Reports 3; true distance 2
  2. B. Reports 2; true distance 1
  3. C. Reports 2; true distance 2
  4. D. Reports 3; true distance 3

Correct answer: A. Reports 3; true distance 2

Dijkstra pops A, then B (2), finalising it, then D = 3, then C (5); the edge C→B would give B = 1, but B is already final, so D stays 3. The real shortest path is A→C→B→D = 5 − 4 + 1 = 2.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic