Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago