mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
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:
parent
12a16d63b7
commit
a212efee5b
|
@ -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]:
|
||||
|
|
Loading…
Reference in New Issue
Block a user