Skip to main content
Module 5 · Dijkstra's Algorithm

Lesson 5 · Implementing compute_path() — Knowledge Checks

Name Date
  1. Why are all distances initialized to 999999 except the start?

    1. A.It is the maximum grid size
    2. B.It represents "infinity / no path yet" — any real distance is smaller, so the first path found always improves it
    3. C.It is a random seed
    4. D.To make the numbers line up

    Answer Why?

  2. What does this loop leave in the variable current?

    1. A.The last node in the graph
    2. B.The unvisited node with the smallest known distance
    3. C.The destination
    4. D.A node chosen at random

    Answer Why?

  3. Why the check `if new_distance < distances[neighbor]` before updating?

    1. A.To skip blocked nodes
    2. B.So a longer path never overwrites a shorter one already found
    3. C.To count the neighbors
    4. D.It is optional and does nothing

    Answer Why?

  4. What does the `if current is None` check protect against?

    1. A.Running out of memory
    2. B.An unreachable destination — no unvisited node has a known distance, so the loop would never end
    3. C.A blocked start node
    4. D.Too many neighbors

    Answer Why?

  5. compute_path returns [(0,0), (0,1), (0,2), (1,2), (2,2)]. How many steps is that?

    1. A.5
    2. B.4
    3. C.3
    4. D.0

    Answer Why?