Data Structures & AlgorithmsVery hardGATE CS · Advanced

Dijkstra's algorithm (a vertex is settled when removed from the priority queue and its distance is never changed afterwards) is run from A on the directed graph with arcs (weights in brackets): A→B (9), A→G (8), B→G (-6), C→B (2), C→D (7), D→F (6), E→A (4), E→F (6), F→D (9), F→G (3), G→C (6), G→D (2). Exactly one arc has a negative weight and there is no negative cycle. By how much does the distance Dijkstra reports for G exceed the true shortest distance from A to G?

  1. A. 5
  2. B. 8
  3. C. 7
  4. D. 3

Correct answer: A. 5

Bellman-Ford gives the true distance 3, but Dijkstra settles a vertex before the negative arc can improve it and reports 8, so the excess is 5.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic