Skip to main content
Module 5 · Dijkstra's Algorithm

Lesson 2 · Dictionaries — Knowledge Checks

Name Date
  1. 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 (row, col) node tuples; values are lists of neighbor tuples
    3. C.Keys are lists; values are tuples
    4. D.Both are single integers

    Answer Why?

  2. Given graph = {(0,0): [(0,1)]}, what does (0,0) in graph return?

    1. A.True
    2. B.False
    3. C.[(0,1)]
    4. D.A KeyError

    Answer Why?

  3. In build_grid_graph, why is each neighbor guarded by an if (like `if row > 0`)?

    1. A.To make the code shorter
    2. B.To keep neighbors inside the grid — a corner or edge node has no neighbor off the grid
    3. C.To skip blocked nodes
    4. D.It has no effect

    Answer Why?

  4. To block node (1,1), what two things must happen to the graph dictionary?

    1. A.Just delete the key (1,1)
    2. B.Delete the key (1,1) AND remove (1,1) from every other node's neighbor list
    3. C.Set graph[(1,1)] to an empty list
    4. D.Nothing — blocked nodes are ignored automatically

    Answer Why?