Lesson 4 · The Manhattan Algorithm — Knowledge ChecksAnswer key
Why can't the robot use a straight diagonal to shorten the trip?
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.
Hand-tracing (2,0) → (2,3), what path do you get?
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.
Why does the stage-1 function return [] for (3,3) → (1,0)?
Stage 1 only handles increasing row/column. Moving up or left needs the two decreasing loops we add next.
For a trip that goes up and to the right, how many of the four while loops actually run?
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.
What does compute_path((2, 2), (2, 2)) return, and why?
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.