how to get the single source shortest path problem for a directed weighted graph using Dijkstra’s algorithm. From the txt.file which looks like: 6 1 2 10 3 0 4 0 5 3 6 8 2 1 0 3 2 4 0 5 4 6 0 3 1 0 2 0 4 9 5 0 6 1 4 1 0 2 0 3 7 5 0 6 2 5 1 0 2 1 3 8 4 2 6 0 6 1 7 2 2 3 0 4 0 5 0
how to get the single source shortest path problem for a directed weighted graph using Dijkstra’s
6
1 2 10 3 0 4 0 5 3 6 8
2 1 0 3 2 4 0 5 4 6 0
3 1 0 2 0 4 9 5 0 6 1
4 1 0 2 0 3 7 5 0 6 2
5 1 0 2 1 3 8 4 2 6 0
6 1 7 2 2 3 0 4 0 5 0
The first line of the file describes the number of vertices (n) of G. For example, the above graph consists of 4 vertices.
Each remaining line of the graph is a list of integers separated by spaces and represents the list of out-neighbors of one vertex. The first number in the line is the name of the vertex. After that, there is a sequence of pairs, consisting of a vertex name and a weight.
For example, the second line of the file:
1 2 8 3 16 4 4
indicates that there is an edge from 1 to 2 of weight 8, an edge from 1 to 3 of weight 16, an edge from 1 to 4 of weight 4, and no other edges from 1.
how would one impliment this into a adjacent matrix or list using java?
Step by step
Solved in 3 steps with 1 images