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.
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 . If a negative-weight cycle exists in a component of the graph that is completely unreachable from the source , the distance estimates for the vertices in that cycle remain at infinity (). 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 , we can keep traversing the cycle to infinitely decrease the path cost. The algorithm runs relaxation for iterations. On the -th iteration, if any edge satisfies , 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 is correct.
Free practice · Your answers on this page are not saved.
