Speed: 500ms
dijkstra.py
def dijkstra(graph, start):distances = {node: float('inf') for node in graph}distances[start] = 0pq = [(0, start)]while pq:curr_dist, curr_node = heapq.heappop(pq)if curr_dist > distances[curr_node]:continuefor neighbor, weight in graph[curr_node]:# Calculate new path costdistance = curr_dist + weightif distance < distances[neighbor]:distances[neighbor] = distanceheapq.heappush(pq, (distance, neighbor))
Priority Queue (Min-Heap)
ACTIVEQueue is empty
Distance Table
ComplexityO(E log V)
Step1 / 0
Current Logic
Select start and end nodes to begin.