Corrected wrong Dijkstra priority queue implementation (#909)

* Corrected wrong DFS implementation

* changed list into hash set for dijkstra priority queue implementation.
This commit is contained in:
zachzhu2016 2019-06-23 08:32:12 -07:00 committed by John Law
parent 12a16d63b7
commit a212efee5b

View File

@ -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]: