Back to problems

Dijkstra's Algorithm Implementation

Algorithm · Google · Medium

Given a weighted graph and a starting vertex, implement Dijkstra's algorithm to determine the minimum distance from that vertex to every other vertex. Assume graph is an adjacency list where each key is a node and each associated value is a list of (neighbor, weight) pairs. Return a mapping from every node to its shortest distance from start. Nodes that cannot be reached should have distance float('inf'). Examples Input: Output: C is reached directly with cost 1; then…

Checking your access…