From a212efee5b44312c8b4b626ae412bacc5f4117fd Mon Sep 17 00:00:00 2001 From: zachzhu2016 <48337051+zachzhu2016@users.noreply.github.com> Date: Sun, 23 Jun 2019 08:32:12 -0700 Subject: [PATCH] Corrected wrong Dijkstra priority queue implementation (#909) * Corrected wrong DFS implementation * changed list into hash set for dijkstra priority queue implementation. --- graphs/dijkstra.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphs/dijkstra.py b/graphs/dijkstra.py index 6b08b28fc..4b6bc347b 100644 --- a/graphs/dijkstra.py +++ b/graphs/dijkstra.py @@ -20,12 +20,12 @@ import heapq def dijkstra(graph, start, end): heap = [(0, start)] # cost from start node,end node - visited = [] + visited = set() while heap: (cost, u) = heapq.heappop(heap) if u in visited: continue - visited.append(u) + visited.add(u) if u == end: return cost for v, c in G[u]: