SSSP - Bellman-Ford Flashcards
Works with Negative weight
yes
Time complexity
O(V*E) as we repeat V-1 times all edges
Relax all edges by V-1 times
w(u) + w(u-v) <= w(v) then update with new weight
Total number of edges in complete graph N
[n(n-1)]/2
Set source vertex 0 and rest all as INFINITY
use relax method V-1 times
Time complexity for complete graph
(nn-1/2) * (n-1)
n-1 nodes
(nnā1) / 2 edges
o(n)^3
Will not work with Cycle with Negative weights
It will work for positive. But not for negative cycles
Normally weights will not change after V-1 times. But if changes then we have negative weight cycles
How it works
Usually given source vertex, order of edges and number of passes.
If source vertex is not given then pick one run by keeping every edge as INFINITY and source 0
And repeat this with N-1 times
https://www.youtube.com/watch?v=FtN3BYH2Zes