Question: Write a python function to implement Dijkstras shortest path algorithm. this was given def dijkstraShortestPath(G,startV): unvisited = [i for i in range] dist = [math.inf
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]
Step by Step Solution
3.48 Rating (164 Votes )
There are 3 Steps involved in it
The provided function contains several errors and is incomplete Lets address and correct them step by step to implement Dijkstras shortest path algori... View full answer
Get step-by-step solutions from verified subject matter experts
