Answered step by step
Verified Expert Solution
Question
1 Approved Answer
# 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
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 ResetStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started