How Dijkstra Locks In Each Intersection Once
A node is locked the first time it is extracted as the minimum from the priority queue, because every still-unlocked node is at least as far away as the just-locked one, so no future relaxation can produce a shorter path to it.
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.
How does Dijkstra's algorithm lock in each intersection exactly once?
A city map where every intersection has a 'final' sign appear in a wave from the start.
You might expect shortest paths to require comparing every intersection over and over — so how can each one be settled after just one look?
Watch a frontier wave expand outward, each node flipping from tentative to locked the first time it's pulled off the priority queue, with a counter proving it never revisits a locked node.
Each intersection is locked exactly once because a node's shortest distance is finalized the moment it becomes the closest unsettled node — and after that, any later route would have to come through a node already at least as far away, so it can never beat the current shortest path.
Most learners first guess that Dijkstra must repeatedly re-check locked nodes against new routes, or compare all remaining intersections every step — and are surprised that one extraction per node is enough.
- Implementation-level heap variants (Fibonacci, pairing, etc.)
- Negative edge weights
- Bidirectional or A* variants
- Formal proofs of correctness
- Time-complexity analysis beyond 'each node locked once'
- 01One intersection, locked foreverslideQuestion
Frame the problem: a small city grid with intersections as nodes and streets (with travel times) as weighted edges. Ask why each intersection needs to be 'settled' exactly once, even though many possible routes reach it.
- Each node has many candidate routes, but Dijkstra settles each only once
- Question: what makes the first time a node is chosen also the final time?
- Focus on a single driving question, not on heap implementation
- 02Predict the first intersection to lockinteractivePrediction
Show a small weighted graph and ask the learner to click which intersection they think Dijkstra will lock first, and why.
- Pick the node you expect to be settled first
- Reason from start distances, not from later hops
- Commit before seeing the algorithm run
- 03The locking waveslideEvidence
Step-by-step animation frames showing each iteration: the priority queue, the node extracted as minimum, neighbors relaxed with updated distances, and the extracted node color-shifting from 'tentative' to 'locked'. A counter tallies locks per node.
- Every node is extracted from the priority queue exactly once
- On extraction, it flips from tentative to locked
- Neighbors' tentative distances shrink via relaxation
- No locked node is ever re-inserted
- 04A node can never improve after lockingslideEvidence
A static two-panel comparison: Panel A shows the frontier as a circle around the start, with the locked node at the center and all other unsettled nodes outside that radius. Panel B shows a hypothetical 'late' path arriving at the same locked node via an unsettled neighbor, with the neighbor shown to be farther from the start than the locked node already is.
- When node v is locked, every still-unlocked node has distance ≥ d(v)
- Any future path into v must pass through some still-unlocked node u
- Path through u would cost at least d(u) + w(u,v) ≥ d(v) + w ≥ d(v)
- So no future path can beat d(v)
- 05Why 'minimum of the remaining' = 'final distance'slideExplanation
Lay out the argument in plain terms: nonnegative weights, the priority queue always holds the smallest current tentative distance, and that smallest one cannot be undercut.
- Nonnegative edge weights: a step away cannot reduce distance
- Min-heap invariant: the top is the shortest tentative distance in the entire graph
- Locking fires at the queue's minimum, which is the global minimum among unsettled nodes
- Once locked, distance is permanent — that is why 'exactly once' is enough
- 06Try it on a twist: weighted but uneveninteractiveTransfer
Learner runs the same algorithm on a new graph where one edge is very long and another very short, and confirms each node still locks exactly once — verifying the explanation travels beyond the first example.
- Operate the algorithm on a fresh graph
- Watch the lock counter stay at one per node
- Notice: uneven weights do not break the once-per-node guarantee
- 07Where 'exactly once' would breakslideBoundary
Show one counterexample: an edge with negative weight. The frontier radius argument collapses because a still-unsettled path could now be shorter, so Dijkstra would settle a node, then later find a shorter path and need to 'unlock' it.
- Negative weights can make a later path through an unsettled node cheaper
- That is why a once-locked node would need to be updated again
- Bellman–Ford is the right tool when this happens
- Dijkstra's 'once and done' guarantee depends on nonnegative weights
- 08Locked once, locked foreverslideResolution
Directly answer the driving question and tie the scenes together into a one-sentence mental model.
- Each intersection is locked exactly once: when it first becomes the minimum-distance unsettled node
- Because every still-unsettled node is at least as far as the locked one, no later route can undercut it
- The min-heap pulls each node out exactly once, and that extraction is the lock event
- Nonnegative weights are the quiet precondition that makes 'once' sufficient
Discussion threads for a Stage aren't available yet.