Dijkstra

Initialize dist = [inf] * n Place start in a min heap For all its neighbors update the dist[v] = dist[u] + d if dist[v] > dist[u] + d and add to min heap # O(V + E*log(V)) dist = [inf] * (n) dist[src] = 0 mi_heap = [[0, src]] visited = set() while mi_heap: dist, u = heappop(mi_heap) visited.add(u) for v, t in adj[u]: if v in visited: continue if dist[u] + t < dist[v]: dist[v] = dist[u] + t heappush(mi_heap, [dist[v], v]) Problems 743....

February 23, 2024 · 2 min · 243 words · Me

Single Source Shortest Path Algorithms

Dijkstra’s single shource shortest path Bellman Ford SPFA (Shortest Path Faster Algorithm)

February 23, 2024 · 1 min · 12 words · Me