Skip to main content
Module 6 · Dijkstra's Algorithm (optional)

Lesson 6-4 · Drive It — Knowledge ChecksAnswer key

Correct answers are marked and the explanation follows each question.

  1. How much of the driving code changes between the BFS run and the Dijkstra run?

    1. A.drive_path() needs a weight parameter
    2. B.None of it — the planner returns a list of intersections either way, and drive_path() drives lists✓
    3. C.turn_to() has to know about the slow segment
    4. D.track_to_intersection() runs slower on purpose

    The plan-versus-drive split from Lesson 4-0 pays off a third time. The driving functions never knew what a path meant, so a path chosen for cost instead of steps is just another list.

  2. A team's Dijkstra run takes 5 steps and 21 seconds; their BFS run takes 3 steps and 29 seconds. A normal block is about 4 seconds. Do the numbers make sense?

    1. A.No — more steps must take more time
    2. B.Yes — 5 normal blocks is about 20 s; 2 normal blocks plus a weight-5 segment is about 28 s✓
    3. C.No — BFS should always be faster
    4. D.Only if the battery was changed between runs

    Cost predicts time: 5 blocks' worth against 7 blocks' worth, at about 4 seconds a block. The stopwatch agreeing with the cost column is the point of the lesson.

  3. Both runs produce the same path and the same time. What is the most likely cause?

    1. A.Dijkstra is broken
    2. B.SLOW_SEGMENT was not typed in (or its weight is 3 or less), so the two planners have no reason to disagree✓
    3. C.The robot is too fast
    4. D.drive_path() ignores the planner

    The printed plans before the button show this at once. With no slow edge, or a weight that ties with the detour, Dijkstra and BFS agree — as they should.