Question: Use Dijkstras algorithm to implement a program that computes the shortest distance between two nodes of an undirected weighted graph. Once Dijsktras algorithm has executed,
Use Dijkstras algorithm to implement a program that computes the shortest distance between two nodes of an undirected weighted graph. Once Dijsktras algorithm has executed, use its output to automatically identify a shortest path in the graph. Please use java and a matrix 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.
- Dijkstra's algorithm computes the shortest distance from a selected node v to all the nodes of the graph. whereas in the programming assignment I ask you to compute the shortest distance from a source to a destination.
- Dijkstra's algorithm merely computes the shortest distance; I want you to also identify a shortest path. I will explain how to do this friday at the live session.
- To test your program/ to illustrate that it works, please use the following data. I assume that nodes are US airports (the ten largest airports in the US, as of the most recent survey). and I assume distances are actually airfares (hence they bear little relation to the actual geographic distances).
number of nodes: 10.
source: JFK.
destination: LAX.
airfares:
JFK CLT 80
JFK ORD 250
JFK DEN 310
CLT ORD 80
CLT DFW 260
CLT ATL 350
ATL DFW 60
ATL LAX 120
ORD DEN 70
ORD SFO 200
ORD LAS 310
DFW DEN 70
DEN LAX 280
LAS SEA 110
SEA SFO 210
SFO LAX 190
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).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
