in Algorithms retagged by
705 views
0 votes
0 votes
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 weights

b) Some negative edge weights without negative edge cycle

c) With negative edge cycles
in Algorithms retagged by
705 views

4 Comments

Yes, I know.
0
0
If there is only positive edge weights then we can use either dijkstra or bellman Ford is that so?
0
0
yes...@vipin
1
1

1 Answer

1 vote
1 vote
If only (+)ve edge weight then both will give correct answer.

If there is (-)ve edge weight only then Dikstra's may or may not give correct answer but bellman ford will give correct answer.

If (-) ve edge weight cycle then bellman ford will report it if it is reachable from source and return answer as undefined.

Related questions