Complete the code to initialize the distance to the start node as zero.
distances = {node: float('inf') for node in graph}
distances[start] = [1]In Dijkstra's algorithm, the distance to the start node is set to zero because it is the starting point.
Complete the code to select the unvisited node with the smallest distance.
current_node = min( (node for node in unvisited), key=lambda node: distances[node] ) if unvisited else [1]
If there are no unvisited nodes left, the current node should be None to stop the algorithm.
Fix the error in updating the distance to a neighbor node.
if distances[current_node] + graph[current_node][neighbor] < [1]: distances[neighbor] = distances[current_node] + graph[current_node][neighbor]
The condition checks if the new calculated distance is less than the current known distance to the neighbor.
Fill in the blank to correctly update the previous node.
if distances[current] + graph[current][neighbor] < distances[neighbor]: distances[neighbor] = distances[current] + graph[current][neighbor] previous[neighbor] = [1]
The previous node for the neighbor is set to the current node when a shorter path is found.
Fill all three blanks to build the shortest path from end to start.
path = [] node = [1] while node is not None: path.append(node) node = [2][node] path = path[[3]]
Start from the end node, follow previous nodes back to start, then reverse the path to get the correct order.