retagged by
714 views
2 votes
2 votes
Suppose we have a graph with a negative weight cycle reaching from the source. And if we try to compute shortest path using Dijkstra's algorithm which of the following is likely to happen?

A) May not find shortest path but report the presence of negative cycle

B) Algorithm never terminates may go to an infinite loop

C) Algorithm terminates

D) None
retagged by

3 Answers

Best answer
2 votes
2 votes
B option. Dijkstra algorithm does not check for the presence of negative edged cycle. In fact it assumes no edge weight is negative. If such a cycle exist and is reachable from source, the algorithm goes to an infinite loop.
selected by
1 votes
1 votes
Ans A)

If there is a -ve weight cycle and the graph can reach to -ve weight cycle from the source but not destination, then it will not find any shortest path.For getting a shortest path we have to reach from source to destination. From source when the graph is getting a -ve cycle and then reach the destination vertex then only we can say there exists a shortest path or not.Otherwise we cannot conclude anything.
0 votes
0 votes
The answer is C. Dijkstra's Algorithm will always terminate(when the min-heap used as a priority queue becomes empty).

Moreover, the vertex set of adjacent nodes is computed only once. There might be a case that edge relaxation will be applied to a node even if it is not in the min-heap anymore which might have lead to an infinite loop if its adjacency were computed after the relaxation(remember, it was not in the min-heap when its edge was relaxed).
Answer:

Related questions

0 votes
0 votes
1 answer
3
Vipin Rai asked Nov 11, 2018
712 views
What is the difference between Dijkstra and Bellman Ford algorithm?Will the shortest path given by both be same in following conditions :a) All positive edge weightsb) So...