in Algorithms retagged by
2,929 views
0 votes
0 votes

Consider the following statements given below:
S1 : If a graph contain a negative weight cycle then Dijkstra’s algorithm may or may not terminate.
S2 : Bellman Ford algorithm for every weighted graph which contain two vertices u and v always produces a shortest path.
Which of the above statements are incorrect? 

  1. Only S1
  2. Only S2
  3. Both S1 and S2
  4. None of these
in Algorithms retagged by
2.9k views

3 Comments

Both are incorrect.

Dijkstra will always terminate , relaxation only happens once.

Bellman ford rejects graphs with negative weight cycles. So cannot produce a shortest path.
2
2

 

may or may not terminate. 

              always terminate 

 

weighted graph which contain two vertices u and v always produces a shortest path.

 If A graph is disconnect ?? and there is no edge between u and v ?

 

C ) both S 1 and S2

3
3
Right on , right on
0
0

1 Answer

1 vote
1 vote
both are incorrect

A)Even a graph contain negative edge weight cycle, dijkstra's algorithm will always terminate although shortest path may or may not be correct.

B)Bellman ford algorithm for weighted graph will always give correct result if there exist a path between them
Answer: