Skip to main content
Module 5 · Dijkstra's Algorithm

Lesson 4 · The Dijkstra Class — Knowledge Checks

Name Date
  1. When is self.graph built?

    1. A.The first time you call compute_path
    2. B.Automatically in __init__, when the object is created
    3. C.You must call build_graph yourself after creating the object
    4. D.Every time you access it

    Answer Why?

  2. What does `if (row, col) in self.blocked: continue` do?

    1. A.Adds the node with an empty neighbor list
    2. B.Skips a blocked node so it never becomes a key in the graph
    3. C.Stops the whole loop
    4. D.Marks the node as visited

    Answer Why?

  3. Why leave compute_path as a placeholder for now?

    1. A.Because the algorithm is impossible
    2. B.To test the class structure (constructor and graph) first, before adding the harder algorithm next lesson
    3. C.To save memory
    4. D.It will never be implemented

    Answer Why?

  4. On a 4×4 grid, how many nodes does Dijkstra((0,0), [(1,0),(2,1)]).graph contain?

    1. A.16
    2. B.15
    3. C.14
    4. D.2

    Answer Why?

  5. Why does it matter that Dijkstra's compute_path returns the same type as Manhattan's?

    1. A.It makes the code run faster
    2. B.The Navigator can use either class interchangeably, since it just calls compute_path and gets a list of tuples back
    3. C.It saves disk space
    4. D.It doesn't matter

    Answer Why?