Skip to content
Official PYQ · 2009

GATE CS 2009 Q13 — Shortest Paths (Dijkstra, Bellman-Ford)

Explain with AI

Which of the following statement(s) is/are correct regarding Bellman-Ford shortest path algorithm?

P: Always finds a negative weighted cycle, if one exists.

Q: Finds whether any negative weighted cycle is reachable from the source.

Choose one option
View worked solution

Answer: B

To determine the correctness of the statements, let us analyze how the Bellman-Ford algorithm operates:

  • Statement P: "Always finds a negative weighted cycle, if one exists."
    This statement is incorrect. The Bellman-Ford algorithm is a single-source shortest path algorithm. It computes distances starting from a designated source vertex ss. If a negative-weight cycle exists in a component of the graph that is completely unreachable from the source ss, the distance estimates for the vertices in that cycle remain at infinity (∞\infty). Consequently, the algorithm cannot detect this cycle because no relaxations occur along its edges.
  • Statement Q: "Finds whether any negative weighted cycle is reachable from the source."
    This statement is correct. If a negative-weight cycle is reachable from the source ss, we can keep traversing the cycle to infinitely decrease the path cost. The algorithm runs relaxation for ∣V∣−1|V|-1 iterations. On the ∣V∣|V|-th iteration, if any edge (u,v)(u, v) satisfies d[u]+w(u,v)<d[v]d[u] + w(u, v) < d[v], it indicates that a shorter path has been found, which is only possible if there is a negative-weight cycle reachable from the source.

Thus, only statement QQ is correct.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Shortest Paths (Dijkstra, Bellman-Ford) questions