Graph TheoryD3Phase 3negative-weightsrelaxationcycle-detection

Bellman-Ford

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.

Visualizer
O(1)Bellman-Ford
Directed weighted graph playback with full-edge relaxation rounds, distance updates, and negative-cycle checks.

Nodes / Edges

0 / 0

Round

n/a

Relaxations

0

Result

Processing

Ready

Press Play or Step to start execution.

Progress

rounds 0, reachable 0, relaxations 0

Distances

n/a

Parents

current edge / updated nodeshortest-path tree / reachablenegative cycle edge
No nodes available for visualization.
Bellman-Ford Implementation
Pseudocode + TypeScript
These examples isolate the repeated edge-relaxation idea so the shortest-path updates and negative-cycle check are easy to map back to playback.
pseudocode
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
1.00xNo Run