Data Structures & AlgorithmsVery hardProduct-company placement

The directed graph A→C (5), A→E (7), B→A (5), C→B (5), D→A (5), D→B (-6), E→C (9), E→D (7) has one negative edge but no negative cycle. Dijkstra's algorithm runs from A, finalising each vertex exactly once (no updates to finalised vertices). For which vertices is the computed distance WRONG?

  1. A. None – Dijkstra is still correct
  2. B. B, D
  3. C. B, E
  4. D. B

Correct answer: D. B

True distances (Bellman–Ford): A=0, B=8, C=5, D=14, E=7. Dijkstra finalised A C E B D and gets A=0, B=10, C=5, D=14, E=7; a vertex finalised before the negative edge could improve it keeps a stale value, and so do vertices computed from it.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic