AdvancedAbout 30 min

    Bellman-Ford Algorithm

    Read the full article on Substack

    6 min read.

    Find shortest paths from a source to all vertices, even with negative edge weights. Can also detect negative weight cycles.

    Think of it this way: Imagine rumor spreading in a social network. Each round, everyone tells their neighbors what they've heard. After enough rounds, the shortest path (fewest retellings) stabilizes. Unlike Dijkstra, it works even if some rumors 'reduce' distance (negative weights).

    45-3-226A∞B∞C∞D∞S0

    Pass 1 · badges show the current distance from the source.

    Source S: distance 0, everything else ∞.

    1/24

    Check your understanding

    Answer from memory before you scroll back up. Pulling an idea out of your head is what makes it stay there.

    Run Bellman-Ford

    Sequence

    Order the phases of the algorithm.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    1. 1Drop a step here
    2. 2Drop a step here
    3. 3Drop a step here
    4. 4Drop a step here
    5. 5Drop a step here
    5 pieces left to place

    Quiz

    20 questions
    Question 1 of 20
    Score: 0

    Why does Bellman-Ford run V-1 iterations?

    Done with this lesson?

    Sign in free to keep your progress, streak and quiz scores.

    Keep going