Bellman-Ford Algorithm Simulation

Not started

Algorithm

function BellmanFord(graph, source):
// Initialize distances
for each vertex v in graph:
distance[v] = Infinity
distance[source] = 0
// Relax all edges |V|-1 times
for i from 1 to |V|-1:
for each edge (u,v) with weight w in graph:
if distance[u] + w < distance[v]:
distance[v] = distance[u] + w
// Check for negative weight cycles
for each edge (u,v) with weight w in graph:
if distance[u] + w < distance[v]:
// Graph contains a negative weight cycle
return error
return distance

Click to add nodes. Click two nodes to create an edge with a weight.

NodeDistance