Question: # Dijkstra's algorithm problem Given an adjacency matrix with weights of edges instead of 0 and 1 (if there is no edge between the vertices

# Dijkstra's algorithm problem

# Dijkstra's algorithm problem Given an adjacency matrix with weights of edges

Given an adjacency matrix with weights of edges instead of 0 and 1 (if there is no edge between the vertices that value is replaced with float("inf")) and a pair of vertices find the shortest path between those vertices and output this path, starting with vertex v_from and ending with vertex v_to. Example 1 Nm no adj_matrix = [[float('inf'), 5, 2], [5, float('inf'), float('inf')], [2, float('inf'), float('inf')]] v_from, v_to = 0, 2 # check that your code works correctly on provided example assert dijkstraPath(adj_matrix, v_from, v_to) [0, 2], 'Wrong answer' 4 == Edit code below to solve the task. from heapq import heappop, heappush 1 2 3 4 5 6 def dijkstraPath(adj_matrix, v_from, v_to): graph, n = adj_matrix, len(adj_matrix) # HINT: use a parent array to store a parent for each vertice heap, path = [], [] used = [False for i in range(n)] 7 8 9 10 # YOUR CODE GOES HERE 11 return path Run 12 Reset Given an adjacency matrix with weights of edges instead of 0 and 1 (if there is no edge between the vertices that value is replaced with float("inf")) and a pair of vertices find the shortest path between those vertices and output this path, starting with vertex v_from and ending with vertex v_to. Example 1 Nm no adj_matrix = [[float('inf'), 5, 2], [5, float('inf'), float('inf')], [2, float('inf'), float('inf')]] v_from, v_to = 0, 2 # check that your code works correctly on provided example assert dijkstraPath(adj_matrix, v_from, v_to) [0, 2], 'Wrong answer' 4 == Edit code below to solve the task. from heapq import heappop, heappush 1 2 3 4 5 6 def dijkstraPath(adj_matrix, v_from, v_to): graph, n = adj_matrix, len(adj_matrix) # HINT: use a parent array to store a parent for each vertice heap, path = [], [] used = [False for i in range(n)] 7 8 9 10 # YOUR CODE GOES HERE 11 return path Run 12 Reset

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!