Lesson 4 · The Dijkstra Class — Knowledge ChecksAnswer key
When is self.graph built?
The constructor calls self.build_graph() once, so the graph is stored in self.graph and ready to use as soon as the object exists.
What does `if (row, col) in self.blocked: continue` do?
continue jumps to the next loop iteration, so a blocked node is never added as a key. Combined with the neighbor checks, blocked nodes are fully absent.
Why leave compute_path as a placeholder for now?
Building in stages keeps the load manageable — verify the graph is correct now, then focus entirely on the algorithm in Lesson 5.
On a 4×4 grid, how many nodes does Dijkstra((0,0), [(1,0),(2,1)]).graph contain?
16 total minus 2 blocked = 14. Both blocked nodes are skipped as keys, and removed from all neighbor lists too.
Why does it matter that Dijkstra's compute_path returns the same type as Manhattan's?
A shared interface — same method name, same return type — is what makes Dijkstra a drop-in replacement for Manhattan in the Navigator.