edited by
3,512 views
1 votes
1 votes

All text books and online resources say 

Dijkstra's algorithm need all non negative edge weights

However I feel a bit different, especially after coming across problem asking to build shortest path tree from node aa in following graph:

enter image description here

My shortest path tree after running Dijkstra came like this:

enter image description here

Then why texts say that Dijkstra need all non negative edge weights? I feel that it should be no -ve edge weight cycle reachable from source node. Am I correct with this? or am I missing something here?

edited by

1 Answer

1 votes
1 votes

GRAPH WITH ONLY POSITIVE WT: Dijkstra will work fine

GRAPH WITH NEGATIVE WT EDGES BUT NO NEGATIVE WT CYCLE: Dijkstra may or may not fail

GRAPH WITH NEGATIVE WT CYCLE: Dijkstra surely fails

Why Dijstra will work in -ve edges ?.
It may fail in -ve edge even there is no -ve cycle.

Can u calculate distance from A to C using Dijkstra ?, It will be 2, right ?
But actual shortest distance is 1 only. (Here Dijkstra fails even NO cycle.)

Here whats happening, Observe:-

Dijkstra had 2 choices to go to C from A, It chooses direct path.
It says if I go via B, then i would have to incur ATLEAST 5 cost. (it don't know that in future there may be a -ve edge.)
It thinks, A to B distance itself is 5 and if I go via B then cost would always increase, there is no chance of decrease. but to his surprise I put "-4"

Actually Dijkstra assumes that all edges are +ve. (if u see proof of " correctness of Dijkstra" then first assumption is weights are +ve )

Related questions

1 votes
1 votes
3 answers
3
ankit_thawal asked Jan 25, 2018
1,560 views
I think answer should be Option(B).Path:<s,y><y,x><x,t = 7-3-2=2
1 votes
1 votes
3 answers
4
Warlock lord asked Sep 14, 2017
1,477 views
If we run Dijkstra’s algorithm to find single source shortest path for the above edge weighted directed graph with ‘8’ as source. In what order do the nodes get inc...