Data Structures & AlgorithmsHardGATE CS · Amazon

A weighted digraph has edges S→A (2), S→B (5), A→C (4), B→A (−4), B→C (1) and C→T (1). Textbook Dijkstra (a vertex's distance is final once it is extracted) is run from S. Which statement is correct?

  1. A. Dijkstra gives d(T) = 6; the true shortest distance is 6
  2. B. Dijkstra gives d(T) = 7; the true shortest distance is 6
  3. C. Dijkstra gives d(T) = 7; the true shortest distance is 7
  4. D. Dijkstra gives d(T) = 7; the true shortest distance is 5

Correct answer: B. Dijkstra gives d(T) = 7; the true shortest distance is 6

Dijkstra finalises A at 2 and never revisits it when the negative edge B→A would improve it to 1, so C = 6 and T = 7. The true shortest path is S→B→A→C→T = 5 − 4 + 4 + 1 = 6, so negative edges break the greedy proof.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic