Skip to content

Commit a212efe

Browse files
ziyzhupoyea
authored andcommitted
Corrected wrong Dijkstra priority queue implementation (#909)
* Corrected wrong DFS implementation * changed list into hash set for dijkstra priority queue implementation.
1 parent 12a16d6 commit a212efe

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

graphs/dijkstra.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
def dijkstra(graph, start, end):
2222
heap = [(0, start)] # cost from start node,end node
23-
visited = []
23+
visited = set()
2424
while heap:
2525
(cost, u) = heapq.heappop(heap)
2626
if u in visited:
2727
continue
28-
visited.append(u)
28+
visited.add(u)
2929
if u == end:
3030
return cost
3131
for v, c in G[u]:

0 commit comments

Comments
 (0)