Back to Discover
Curiosity

Why Dijkstra's Nodes Stay Locked

A node is locked the moment it is extracted because every alternative path to it would have to detour through an unvisited node and therefore be longer, making its tentative distance permanent.

Before you enter

A complete interactive classroom, not just a preview.

Start when you are ready to enter this Stage's 8 scenes and explore, respond, and learn as you go.

8
Scenes
16 min
Estimated
Content language: en-US
Start this Stage
Sign-in may be required to play
What happens inside
  1. 01The Locked-Node Mysteryslide
    Question

    Set up the driving question: Dijkstra extracts nodes one by one, but what guarantees that once a node is popped, its distance is final?

    • Dijkstra marks each node as visited once it is extracted
    • The shortest distance to a visited node never changes afterward
    • We need to find the single reason this is always true
  2. 02Commit to a First Guessquiz
    Prediction

    Before the trace, ask the learner to pick the rule they think is really doing the locking work.

    • Choose what actually prevents a locked node from being improved
  3. 03Tracing a Small Graph Step by Stepslide
    Evidence

    Walk through Dijkstra on a five-node graph with non-negative weights, showing the min-heap state, the tentative distances, and the extraction order.

    • Each extraction picks the smallest tentative distance among unvisited nodes
    • Relaxations only lower a neighbor's distance, never raise it
    • Once a node is extracted, no later relaxation ever touches it
  4. 04Try to Improve a Locked Nodeinteractive
    Evidence

    An interactive simulation where the learner attempts to relax an already-extracted node by routing through unvisited nodes, and watches the path length only grow.

    • Only unvisited nodes remain in the priority queue
    • Any detour through an unvisited node adds non-negative edge weight
    • The locked node's distance cannot be beaten
  5. 05Why the Distance Is Finalslide
    Explanation

    State the core argument: any alternative path to a locked node must start with an edge from a locked node to an unvisited one, and every such edge contributes non-negative extra cost.

    • A shortest path to a locked node must end with an edge from an unvisited node
    • That edge's weight is at least 0, so the alternative path is at least as long
    • The extracted distance is therefore the global minimum
  6. 06When the Lock Breaksslide
    Boundary

    Show what happens if the assumption fails: a single negative edge weight would let a longer-looking path overtake an already-locked node, which is why Dijkstra requires non-negative weights.

    • Negative edge weights can shorten a path through an unvisited node
    • Dijkstra's finalization argument assumes each remaining edge is non-negative
    • This is exactly why Bellman-Ford is needed for negative weights
  7. 07Apply the Rule to a New Graphinteractive
    Transfer

    A new weighted graph with an obvious extracted order; the learner must identify which node settles next and confirm that no later relaxation can improve it.

    • Identify the next extractable node
    • Predict the final distance after extraction
    • Verify that detouring through unvisited nodes cannot improve it
  8. 08Answering the Driving Questionslide
    Resolution

    Directly answer: a node is locked because any competing path would have to enter it through an unvisited node via a non-negative edge, so the first extracted distance is already the shortest possible.

    • The lock is a consequence of non-negative weights and the min-heap extraction order
    • It is not a heuristic or a convenience — it is a guarantee
    • This guarantee is what makes Dijkstra correct in O((V+E) log V)
Discussion

Discussion threads for a Stage aren't available yet.

Where this leads
Explore more

More in Math & Logic

See all