View the step-by-step solution to:

Question

# Use Dijkstra's algorithm to implement a program that computes the shortest distance between two nodes of

an undirected weighted graph. Once Dijsktra's algorithm has executed, use its output to automatically identify a shortest path in the graph.

Input:

• The graph, given by providing in sequence: the number of nodes, then a sequence of arcs with associated length.
• The source.
• The destination.

Output:

• The shortest distance.
• A shortest path.

In order to test your program 3, please use the following data as input :

Assume that nodes are US airports and the number of nodes is 9. The source node is JFK and the destination node is LAX. [we do not specify an origin and destination. rather, the program prompts the user to designate an origin and destination, and it computes the shortest distanceTherefore, in the screenshots, show an output for the mentioned data but while checking i'll randomly select Source and Destination and hence will want the output based on it]

Suppose the distance as follows:

JFK DEN 300

JFK ORD 150

JFK CLT 100

ORD CLT 30

ORD DEN 70

ORD LAS 310

ORD SFO 300

SFO LAS 50

SFO LAX 120

LAS DEN 240

LAS ATL 70

LAS LAX 150

DEN DFW 40

DEN ATL 90

DEN LAX 400

LAX ATL 320

ATL DFW 60

ATL CLT 350

DFW CLT 260

Hint: the simplest was to represent the weighted graph is by a symmetric 2D matrix, say dist[10,10] where dist(x,y) is the distance between x and y. if there is no flight between x and y, you let dist[x,y] be infinity (i.e. a very large number).

For JFK CLT 100, it could be considered here has an undirected edge between node JFK and CLT, and the length of the edge is 100. That is to say dist(JFK, CLT)=dist(CLT,JFK)=100.

Dijkstra's algorithm is very similar toPrim's algorithm for minimum spanning tree. Like Prim's MST, we generate a SPT... View the full answer

### Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

• ### -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents