retagged by
829 views
1 votes
1 votes
Question was about Single Source shortest path -
We know that Dijkstra may/ may not handle negative edge weights in graph but Bellman Ford can. Also, the time complexity of bellman ford is higher than that of Dijkstra's. Now what if we add a large positive integer to all the weights of the graph, and then simply apply Dijkstra? What is the need of Bellman Ford then?
retagged by

1 Answer

Best answer
3 votes
3 votes

Generally adding a weight changes the length of different paths by different amount. Say one path contains 3 edges and another contains 1 edge, and you increment weight by 1, then length of first path is increased by 3 whereas length of second path is increased by only 1. Below is an example of case where adding a weight approach fails. Shortest path from leftmost node to rightmost node is shown in red.

Before:

After:

selected by

Related questions

1 votes
1 votes
1 answer
1
0 votes
0 votes
0 answers
2
Churchill Khangar asked Nov 23, 2018
155 views
0 votes
0 votes
0 answers
3
Churchill Khangar asked Nov 22, 2018
319 views
0 votes
0 votes
0 answers
4
Churchill Khangar asked Nov 22, 2018
248 views