Skip to main content
Module 4 · Manhattan Navigation

Lesson 4 · The Manhattan Algorithm — Knowledge ChecksAnswer key

Correct answers are marked and the explanation follows each question.

  1. Why can't the robot use a straight diagonal to shorten the trip?

    1. A.Diagonals are slower than straight lines
    2. B.The robot follows grid lines, so it can only move along rows and columns
    3. C.The grid is too small
    4. D.It can — the Manhattan algorithm just chooses not to

    Like walking Manhattan's streets, the robot can't cut through the middle of a block — only along the lines. That's exactly why the distance is row steps + column steps.

  2. Hand-tracing (2,0) → (2,3), what path do you get?

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

    Same row, so no row moves — only three column moves. The start (2,0) is not included, so the path is [(2,1), (2,2), (2,3)]: three steps.

  3. Why does the stage-1 function return [] for (3,3) → (1,0)?

    1. A.append() is broken
    2. B.Both while conditions are False from the start (3 is not < 1, 3 is not < 0), so neither loop runs
    3. C.The start and end are the same
    4. D.It runs forever

    Stage 1 only handles increasing row/column. Moving up or left needs the two decreasing loops we add next.

  4. For a trip that goes up and to the right, how many of the four while loops actually run?

    1. A.All four
    2. B.Two — the north loop and the east loop
    3. C.Just one
    4. D.None — it needs if/else

    At most one row loop (north OR south) and one column loop (east OR west) run for any trip. Up-and-right means north + east; the other two are skipped.

  5. What does compute_path((2, 2), (2, 2)) return, and why?

    1. A.[(2, 2)] — the current position
    2. B.[] — all four loop conditions are False, so nothing is appended
    3. C.An error
    4. D.0

    Start equals destination, so every while condition is False from the start. No loop runs, the path stays empty, and len(path) is 0 — the robot is already there.