DEV Community

Discussion on: Dijkstra's algorithm in python: algorithms for beginners

Collapse
 
neogeomat profile image
neogeomat

The algotithm says

6 Stop, if the destination node has been visited.

in the code

6. Stop, if the smallest distance

among the unvisited nodes is infinity.

if distances[current_vertex] == inf:
break

The code visits all nodes even after the destination has been visited.