Back to Discover
Curiosity

Why does Dijkstra only need to check each node once?

The proof that Dijkstra's one-shot extraction is correct: the invariant maintained by the priority queue, the role of non-negative edge weights, and the geometric meaning of the settled frontier.

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: zh-CN
Start this Stage
Sign-in may be required to play
What happens inside
  1. 01The 5-Node Puzzleslide
    Question

    A weighted graph with five nodes is displayed. The classic Dijkstra execution is traced: at each step, one node is extracted from the priority queue and its distance marked final. The learner is asked to pinpoint the moment that guarantees correctness.

    • Five-node weighted graph with a source node
    • Priority queue contents shown before each extraction
    • Extracted node is shaded as 'settled' with its distance frozen
  2. 02Commit to a Reasonquiz
    Prediction

    Before the mechanism is revealed, the learner chooses which invariant protects the popped distance from being beaten later.

    • Make one independent choice about why the popped distance is already minimal
  3. 03Step the Simulatorinteractive
    Evidence

    An interactive simulation lets the learner manually advance Dijkstra on the same 5-node graph, watching the priority queue update and the frontier expand.

    • Click 'Extract' to pop the smallest distance from the queue
    • Observe the queue ranking of every remaining target distance
    • Note that no extracted distance ever changes later
  4. 04Tracking a Rival Pathslide
    Evidence

    A second visualization overlays an attempted 'shorter' route to an already-settled node, showing that it must re-enter the frontier through an edge that adds non-negative cost — so it can never undercut the popped value.

    • Highlight the settled node in gold
    • Draw a rival route through the still-unsettled region
    • Label the crossing edge with its non-negative weight
  5. 05Break It with a Negative Edgeinteractive
    Boundary

    The learner drags a slider to set one edge weight to a negative value and re-runs the simulation to watch a settled node's distance get beaten later — the single-check guarantee collapses.

    • Slider sets one frontier edge to negative
    • Simulator re-extracts and reveals the violated distance
    • Confirms that non-negative weights are the load-bearing assumption
  6. 06The Frontier Invariantslide
    Explanation

    A clean statement of the invariant: when a node is popped, every still-unexplored path to it must cross an unsettled edge, and that crossing can only add non-negative length. Hence the popped distance is already minimal.

    • Formal statement of the invariant over the settled set S
    • Role of non-negative edge weights in sealing the frontier
    • Connection to a wavefront expanding outward from the source
  7. 07Apply It to a New Graphquiz
    Transfer

    A fresh weighted graph is shown. The learner picks which candidate from the priority queue can be safely settled next, applying the frontier reasoning to a new topology.

    • Inspect the new graph and its current priority queue
    • Identify the safe next extraction using the invariant
  8. 08Why One Check Sufficesslide
    Resolution

    The driving question is answered directly: Dijkstra locks in a distance on first extraction because any later improvement would have to travel through a remaining, non-negatively-weighted edge, which cannot undercut what is already the queue's smallest value.

    • Direct answer restating the frontier argument
    • Non-negative weights as the necessary precondition
    • Single-check settlement as a consequence, not an assumption
Discussion

Discussion threads for a Stage aren't available yet.

Where this leads

This path ends here.

Explore more

More in Technology & Computing

See all