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.
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.
What keeps each Dijkstra node locked after its first extraction?
You've seen Dijkstra's algorithm pop nodes one by one. But why does each node never get re-extracted or overwritten once it's chosen?
It feels like a guess: 'we trust the first distance we set.' Is that trust justified, or just convenient?
A step-by-step trace of Dijkstra's algorithm on a small weighted graph, showing why a locked node's distance cannot be improved later.
The shortest path to a finalized node is already complete, so its distance is final — and that single fact is what keeps every node locked.
A reasonable first guess is that a node is locked because it has the smallest currently visible distance, or because it was marked 'visited' — but neither of those alone explains why no future step can improve it.
- negative-weight edges and the Bellman-Ford algorithm
- Fibonacci-heap and priority-queue implementation details
- proofs of correctness beyond the finalization argument
- A* and other heuristic variants
- 01The Locked-Node MysteryslideQuestion
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
- 02Commit to a First GuessquizPrediction
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
- 03Tracing a Small Graph Step by StepslideEvidence
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
- 04Try to Improve a Locked NodeinteractiveEvidence
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
- 05Why the Distance Is FinalslideExplanation
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
- 06When the Lock BreaksslideBoundary
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
- 07Apply the Rule to a New GraphinteractiveTransfer
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
- 08Answering the Driving QuestionslideResolution
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 threads for a Stage aren't available yet.