Data Structures & AlgorithmsModerateWipro · Accenture pattern

Which single-source shortest path algorithm can detect a negative-weight cycle reachable from the source?

  1. A. Prim
  2. B. BFS
  3. C. Dijkstra
  4. D. Bellman–Ford

Correct answer: D. Bellman–Ford

After V − 1 rounds of relaxation, Bellman–Ford makes one more pass: if any edge can still be relaxed, a negative cycle is reachable. Dijkstra assumes non-negative weights, and Prim builds spanning trees, not paths.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic