Lesson 5-3 · From Pencil to Program — Knowledge ChecksAnswer key
On a 3×3 grid, how many neighbors does the interior node (1,1) have?
(1,1) connects left, right, down, and up — (0,1), (2,1), (1,0), (1,2). No diagonals, so four neighbors.
After (1,1) is blocked, how many neighbors does (0,1) have?
(0,1) used to connect to (0,0), (0,2), and (1,1). With (1,1) removed, only two neighbors remain.
In our graph dictionary, what are the keys and what are the values?
Each node is a tuple key, and its value is the list of nodes it connects to — the Python version of the paper graph.
Given distance = {(2,2): 0, (1,2): 1}, what does (1,2) in distance return, and what does it mean?
in checks whether a key exists. (1,2) is a key, so it returns True: it already has a number, and must not get another. distance[(1,2)] would give 1, the number itself.