Data Structures & AlgorithmsHardProduct Company SDE · graph round

Problem: A directed graph with V vertices is relaxed with Bellman-Ford. After V - 1 full rounds of relaxing all edges, one more round still lowers some distance. What does this prove?

  1. A. The shortest path to that vertex has one more edge than allowed
  2. B. The graph is disconnected from the source
  3. C. A negative cycle is reachable from the source
  4. D. All edge weights must be positive

Correct answer: C. A negative cycle is reachable from the source

Any simple shortest path has at most V - 1 edges, so a further improvement can only happen if the walk loops through a negative cycle reachable from the source.

More Coding Interview Problems questions

Exams that ask this topic