Lecture 14 Finger Exercise

The questions below are due on Friday May 08, 2026; 11:59:00 PM.
 
You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.

Consider the weighted directed graph below for the following questions.

Question 1. When running Dijkstra's algorithm from source S, which edge(s) have NOT yet been considered at the moment when the shortest distance from S to G is guaranteed? Select all that apply.

Question 2. Ben Bitdiddle tried to reproduce the code from lecture for Dijkstra's algorithm, and came up with the following. While much of it is correct, there is a bug in it. (You may assume he's correctly using the helper functions remove_min(), neighbors(), and update_node().)

def dijkstra(graph, start, goal):
    queue = [(0, [start])]
    finished = set()

    while len(queue) > 0:
        # get a path off the true frontier
        cost, path = remove_min(queue)
        node = path[-1]

        # return when goal comes off of priority queue
        if node == goal:
            return cost, path

        # update paths to neighbors on priority queue
        for next_node, weight in neighbors(graph, node):
            if next_node not in finished:
                finished.add(next_node)
                new_cost = cost + weight
                new_path = path + [next_node]
                update_node(queue, new_path, new_cost)

    return None

If Ben were to run his dijkstra() implementation with S as start and G as goal:

  • What result would his function return?
  • How many times would next_node be assigned to G before the function returns? Assume that among paths with equal cost on the queue, remove_min() prioritizes paths that end on a letter that is earlier in the alphabet.

Specify your answer as a dict with the key "result" mapping to a tuple, and the key "num_visits" mapping to an int. The "result" tuple should be of the form (cost, path), where cost is an int and path is a list of strs that begins with "S" and ends with "G".

Example format:

{
    "result": (100, ["S", "A", "B", "C", "G"]),
    "num_visits": 100,
}