Lesson 3 · Dijkstra's Algorithm — The Concept — Knowledge ChecksAnswer key
What does the previous dictionary store?
previous records each node's predecessor on the shortest path. Tracing it backward from the destination reconstructs the route.
Which unvisited node does Dijkstra visit next?
Dijkstra has no notion of 'distance to the destination.' It always expands the nearest unvisited node measured from the start.
At step 7, visiting (2,1) offers (2,2) a distance of 3+1=4, but (2,2) already has distance 4. What happens?
Dijkstra only updates when the new path is strictly shorter. 4 is not less than 4, so (2,2) keeps its existing distance and previous.
Why must the reconstructed path be reversed?
You follow previous backward (destination → start), so the collected list is reversed. Flipping it gives the forward path the robot drives.
On a clear grid with no obstacles, how does Dijkstra's path length compare to Manhattan's?
With no obstacles, both find an optimal path of equal step count. Dijkstra's real advantage shows up only when obstacles are present.