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
A
Neither P nor Q
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
Both P and Q
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
P only
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
Q only
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
Open in App
Solution
The correct option is D Q only
Bellman-Ford shortest path algorithm always finds any negative weighted cycle which is reachable from the source. If the negative weighted cycle is not reachable then, Bellman Ford algorithm not able to find that cycle.