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

Lesson 6-2 · Weights in the Graph — Knowledge ChecksAnswer key

Correct answers are marked and the explanation follows each question.

  1. SLOW_EDGES holds ((0, 1), (0, 2), 5). What do weight((0, 2), (0, 1)) and weight((1, 1), (1, 2)) return?

    1. A.5 and 5
    2. B.5 and 1 — the slow segment matches in either order; a segment not in the list is a normal block✓
    3. C.1 and 1
    4. D.An error, because the first pair is backwards

    The or in the if makes the match direction-free; the final return 1 is the default for every ordinary segment.

  2. Why does path_cost() need the position parameter, when the path is right there?

    1. A.It does not; position is unused
    2. B.The path excludes the start (Lesson 4-3's promise 1), so the first segment runs from position to path[0], and only the caller knows position✓
    3. C.To check the path is not empty
    4. D.Because weight() requires three arguments

    Every planner in the course returns the intersections to drive TO. The segment from where the robot is to the first of those is part of the trip, and its weight counts.

  3. BFS passes every Module 5 property on the slow grid and fails only the cost check. What does that tell you?

    1. A.BFS is broken and must be rewritten from scratch
    2. B.BFS does exactly what it promises — fewest steps — and cost is a different thing it was never asked to minimize✓
    3. C.The harness is wrong
    4. D.The slow segment should be blocked instead

    A property test tells you precisely which promise failed. The path is valid, connected, unblocked and shortest in steps. It is not cheapest — and nothing in BFS ever looks at a weight.