edited by
4,743 views
5 5 votes

Consider the following statements with respect to a directed graph G in which edges can have positive or negative edge length but that has no negative cycles:
S1  : The Bellman-Ford algorithm correctly computes shortest path lengths from a given origin ‘s’ to every other vertex ‘v ’.
S2 : The Floyd-Warshall algorithm correctly computes shortest path lengths between every pair of vertices.
Which of them is correct?

3 Answers

3 3 votes
Both will be correct.

S1. Bellman Ford works correctly if there are no negative weight cycles

S2. Floyd Warshall Algorithm uses Dynamic programming , therefore all the possiblities will be considered. So given that if shortest path exist(i.e., no negative weight cycles), then Floyd Warshall will surely find it.
0 0 votes

Bellman Ford is compatible even if there are negative edges or negative edge cycles, to find the Single Source Shortest Path.

Time Complexity: O(V^2)

Whereas The Floyd -Warshall Algorithm is Used to find all Pair Shortest Path.

Time Complexity: O(V^3)

BOTH ARE TRUE

Position:
Show:

Related questions

2 2 votes
4 4 answers
2.5k
2.5k views
Bongbirdie asked Apr 6, 2017
2,521 views
Is the below statement correct:Bellman Ford finds all negative weight cycles in the graph.This is true or false?
0 0 votes
0 0 answers
1.3k
1.3k views
srestha asked Aug 26, 2018
1,334 views
What are the asymptotic running times for INSERT, EXTRACT-MIN, and DECREASE-KEY of Floyd Warshall and Bellman Ford Algorithm?
2 2 votes
0 0 answers
1.1k
1.1k views
Chhotu asked Nov 3, 2017
1,101 views
Hi Guys,As everyone knows Bellman Ford Algorithm works on DP approach. The algorithm calculate shortest paths in bottom-up manner. It first calculates the shortest distan...
1 1 vote
1 answers 1 answer
1.8k
1.8k views
Sandy Sharma asked Aug 3, 2018
1,848 views
What is the reason behind it? How do we find an optimal substructure and overlapping sub problems in this ? In which line of code memoization is done? BELLMAN-FORD(G,w,s)...