

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Welcome to DS&A 2
incomplete
2: Dijkstra's Algorithm
incomplete
3: Dijkstra's: Get Path
incomplete
4: Weighted Graphs
incomplete
5: Next Nearest Node
incomplete
6: Dijkstra's Algorithm
incomplete
7: Dijkstra's Algorithm Review
incomplete
8: Dijkstra's Time Complexity
incomplete
9: Greedy Algorithms
incomplete
10: Dijkstra's vs. DFS
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
We also need a function that finds the "next nearest node," i.e. the next node to visit; this is a critical part of Dijkstra's algorithm.
Complete the next_nearest_node function. It returns the closest unvisited node.
This function accepts a distances dictionary, which is a mapping of:
node label -> distance
And it returns the "node label" (a string) with the smallest "distance" value that exists in the unvisited set. If there are no eligible nodes, it returns None.
For example, given:
distances = {'Hartford': 7, 'New Haven': 2, 'Greenwich': 3}unvisited = {'Hartford', 'Greenwich'}The function should return 'Greenwich', since it has the smallest distance (3) among the unvisited nodes.