Lesson 66 of 86AdvancedPro Interactive Lesson

Bellman–Ford and Negative Edge Weights

Track edge relaxations and check what a further improvement implies about reachable negative cycles.

Core Intuition & How It Works

Bellman–Ford computes single-source shortest paths even when edges have negative weights by relaxing every edge V - 1 times. An extra Vth relaxation pass that still reduces any distance detects a reachable negative-weight cycle.

In the Byte Sized Algorithms interactive classroom, you can step forward and backward through this algorithm with your keyboard while watching the visual diagram, memory state, and highlighted pseudocode update together.

Time & Space Complexity

MetricComplexity
Time ComplexityO(V × E)
Space ComplexityO(V)
Topic ChapterChapter 12: Shortest Paths & Spanning Trees
Difficulty LevelAdvanced

Key Pattern to Recognize

Terminate early if an entire relaxation pass makes zero updates, and check for negative cycles on pass V.

Common Pitfalls & Edge Cases

Using Bellman–Ford when all weights are non-negative (Dijkstra is much faster) or ignoring overflow when relaxing from Infinity.

Real-World & Technical Interview Applications

Currency arbitrage detection, distance-vector routing (RIP), and Johnson’s all-pairs shortest-path preprocessing.

Unlock the full course

All 86 lessons across 15 chapters

View pricing

Delete account

This permanently deletes your account and ends any Pro access.