Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please provide a working code in Python, and NOT pseudocode. Dijkstra's shortest path algorithm should be implemented in Python using the following pseudocode. for all

Please provide a working code in Python, and NOT pseudocode.

image text in transcribedimage text in transcribed

Dijkstra's shortest path algorithm should be implemented in Python using the following pseudocode. for all u in V: dist(u) = Infinity prev(u) = nil dist(s) = 0 A = makequeue(V) (using dist-values as keys) while A is not empty: u = deletemin(A) for all edges (u; v) 2 E: if dist(v) > dist(u) + I(u; v): dist(v) = dist(u) + I(u; v) prev(v) = u decreasekey(A; v) You may use the HeapDict priority queue implementation that works like a dictionary, and also allows for both insert and decrease key operations by simply setting the dictionary key to a given value. popitem can be used for delete min. The code should take as input a graph with weights, and a starting vertex v, and it should output the shortest path length from v to all vertices in the graph, and you should also output the short path as a list of vertices, such as by using the prev pointers in the pseudocode. The input graph will be shown as a pair of edges and weights. For example: An input that looks like the following: 124 142 232 243 253 421 434 455 531 Means that the edge (5, 3) has the weight of 1. The output appears as: 1: 0, [1] 2: 3, [1, 4, 2] 3: 5, [1, 4, 2, 3] 4: 2, [1, 4] 5: 6, [1, 4, 2, 5] The output is shown as distance from v

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

9. Mohawk Industries Inc.

Answered: 1 week ago