Skip to main content
Module 5 · Pathfinding Around Obstacles

Lesson 5-3 · From Pencil to Program — Knowledge ChecksAnswer key

Correct answers are marked and the explanation follows each question.

  1. On a 3×3 grid, how many neighbors does the interior node (1,1) have?

    1. A.2
    2. B.3
    3. C.4✓
    4. D.8

    (1,1) connects left, right, down, and up — (0,1), (2,1), (1,0), (1,2). No diagonals, so four neighbors.

  2. After (1,1) is blocked, how many neighbors does (0,1) have?

    1. A.3 — nothing changed
    2. B.2 — it lost its connection to the right, to (1,1)✓
    3. C.4
    4. D.0

    (0,1) used to connect to (0,0), (0,2), and (1,1). With (1,1) removed, only two neighbors remain.

  3. In our graph dictionary, what are the keys and what are the values?

    1. A.Keys are numbers; values are strings
    2. B.Keys are (x, y) node tuples; values are lists of neighbor tuples✓
    3. C.Keys are lists; values are tuples
    4. D.Both are single integers

    Each node is a tuple key, and its value is the list of nodes it connects to — the Python version of the paper graph.

  4. Given distance = {(2,2): 0, (1,2): 1}, what does (1,2) in distance return, and what does it mean?

    1. A.True: (1,2) already has a number✓
    2. B.False: (1,2) is blocked
    3. C.1: its number
    4. D.A KeyError

    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.