Write a python function to implement Dijkstras shortest path algorithm. this was given def dijkstraShortestPath(G,startV): unvisited =
Fantastic news! We've Found the answer you've been seeking!
Question:
Write a python function to implement Dijkstra’s shortest path algorithm.
this was given
def dijkstraShortestPath(G,startV):
unvisited = [i for i in range]
dist = [math.inf for v in G]
path = [-1 for v in G]
dist[startV]=0
while len(unvisited)>0:
currentV= unvistited[0]
for v in unvisited[1:]:
if dist[v]< dist[currentV]:
currentV = v
#remove currentV from unvisited
for edge in G[currentV]:
currentV, edgeweight = edge[0], edge[1]
Related Book For
Data Structures and Algorithms in Python
ISBN: 978-1118290279
1st edition
Authors: Michael T. Goodrich , Roberto Tamassia, Michael H. Goldwasser
Posted Date: