Test yourself
Consider the following graph..
After the first iteration, what are the distances to the nodes 1, 3 and 5 respectively
How many negative edge cycles are present in the graph ?
Bellman-Ford's algorithm helps compute the minimum spanning tree of a directed graph, which can have negative edges and negative edge cycles
If there is a cycle in the graph shose sum of edges in negative, then say djikstra's algorithm would keep going in an infinite loop as every time it runs the distance keeps getting shorter and shorter on adding the cycle.
1) Choose the starting vertex from where you want to calculate the distance to every other node. In the beginning, initialize the distance from the starting node to every node except itself to be infinity. The distance of the node from itself would be zero.
2) Now go through every edge - this can be done by going to every vertex and considering all its outgoing edges
For every edge A-B,