02Key parts
The pieces you will see
- dist[v]
- The best distance from the start to v found so far. Starts at ∞ for everything except the start (0).
- settled
- A node whose distance is final. Each node is settled exactly once.
- relaxation
- Checking an edge u → v: if dist[u] + w beats dist[v], update dist[v] and remember u as v's predecessor.
- min-heap
- A priority queue that hands back the unsettled node with the smallest tentative distance.
03See it work
Watch the distances settle
Watch the heap panel: a node can be pushed several times as its distance improves. The older, larger entries become stale and are skipped when popped. That "lazy" approach is simpler than updating entries in place.
04Predict
Your turn: settle and relax
Predict which node is settled next and whether each edge improves a distance.
Make 6 predictions: step forward and answer each question before the next step plays.
0 of 6 made05Try it
Break the assumption
Pick the graph with a negative edge. Dijkstra settles B at distance 2 straight away, before discovering that going through C would cost 5 − 4 = 1. The visualiser finishes, then checks the true distances and names the ones it got wrong.
06Check yourself
Check yourself
Question 1 of 5
Which node does Dijkstra settle next?
Your answer comes back in Review in a few days, so it sticks.
Question 2 of 5
dist[C] = 7 and an edge B → C has weight 2, with dist[B] = 4. What does relaxing the edge do?
Question 3 of 5
Why can Dijkstra give wrong answers with a negative edge?
Question 4 of 5
With a binary heap, about how long does Dijkstra take on V nodes and E edges?
Question 5 of 5
A graph has one edge of weight −3 and no negative cycle. Does Dijkstra always find the shortest distances?
07Explain it back
Say it in your own words
How does Dijkstra’s algorithm choose which node to settle next, and why is that node’s distance final?
08Recap
What to remember
- Dijkstra settles nodes in increasing order of distance, relaxing each settled node's edges.
- A min-heap finds the closest unsettled node in O(log V); stale entries are skipped.
- It is correct only without negative edges; Bellman–Ford handles those.
- For every pair at once, all-pairs shortest paths runs Floyd–Warshall.
- It is breadth-first search with "rings of distance" instead of "rings of steps", and the basis of routing and A* search.