Edge-relaxation rounds including negative-cycle detection semantics.
Easy Explanation
Bellman-Ford relaxes edges repeatedly to find shortest paths and can detect negative-weight cycles.
Nodes / Edges
0 / 0
Round
n/a
Relaxations
0
Result
Processing
Press Play or Step to start execution.
Progress
rounds 0, reachable 0, relaxations 0
Distances
n/a
Parents
function bellman_ford(edges, node_count, start):
distance[start] <- 0
distance[others] <- infinity
parent[*] <- none
repeat node_count - 1 times:
changed <- false
for (u, v, w) in edges:
if distance[u] is infinity:
continue
candidate <- distance[u] + w
if candidate < distance[v]:
distance[v] <- candidate
parent[v] <- u
changed <- true
if not changed:
break
for (u, v, w) in edges:
if distance[u] + w < distance[v]:
return negative_cycle
return distance, parent