Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Dijkstra's algorithm apply even if there is only one negative weight edge?

Will Dijkstra's Algorithm work if the digraph has only one negative weight edge and does not contain negative weight cycles?

like image 257
jsh6303 Avatar asked Nov 21 '13 19:11

jsh6303


People also ask

Does Dijkstra's algorithm work if any edges have negative weights?

Dijkstra's algorithm solves the shortest-path problem for any weighted, directed graph with non-negative weights. It can handle graphs consisting of cycles, but negative weights will cause this algorithm to produce incorrect results.

Which edge is not accepted in Dijkstra algorithm?

Since Dijkstra follows a Greedy Approach, once a node is marked as visited it cannot be reconsidered even if there is another path with less cost or distance. This issue arises only if there exists a negative weight or edge in the graph.

What is the only requirement for Dijkstra's algorithm?

Requirements. Dijkstra's Algorithm can only work with graphs that have positive weights. This is because, during the process, the weights of the edges have to be added to find the shortest path. If there is a negative weight in the graph, then the algorithm will not work properly.


1 Answers

No. Dijkstra's algorithm is greedy. It assumes path weights are strictly increasing.

Consider the following graph. S→A→E is optimal, but the Dijkstra's will return S→B→E.

troublesome graph

like image 167
John Kugelman Avatar answered Sep 21 '22 06:09

John Kugelman