Question

Dijkstra’s Algorithm: You have to implement the Dijkstra’s algorithm and apply it on the graph provided below.

You have to take the input from the user as an adjacency matrix representing the graph, the source, the destination. Then you have to apply the Dijkstra’s algorithm to find the shortest path from the source and the destination, and  find the shortest route between the source and the destination.

For the input you have to read it from a file. It will have the number of nodes and the adjacency matrix as given below. The source and the destination can be given as an input as a command line

N=5 A B C DE

For the distance not known or for distance from a node to itself can represented as ∞ as shown above.

you can do it in any programming language but please type the code do not write on paper and code must be working


N=5 A B C DE
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The following code has been run in "Eclipse". Just save the java file with "ShortestPath.java" and compile and run.

1// A Java program for Dijkstras single source shortest path algorithm 2 // The program is for adjacency matrix representati

39 void dijkstra(int graph[][], int src) 40 41 42 int dist[] = new int [V]; // The output array dist[i] will hold // the sho

dist[u] Integer.MAX VALUE && dist[u]+graph[u][v] < dist[v]) 78 79 80 81 82 83 84 85 86 87 public static void main (String[] a

OUTPUT:

E-Problems @ Javadoc G Declaration Console terminateds ShortestPath lava Application] CAProgram Files Javaljire1.3.0 181\binl

Add a comment
Know the answer?
Add Answer to:
Dijkstra’s Algorithm: You have to implement the Dijkstra’s algorithm and apply it on the graph provided below. You have to take the input from the user as an adjacency matrix representing the graph,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT