Question: I would really appreciate it if someone could help me with this program. Basically I have to use Dijkstra algorithm to find shortest path lengths

I would really appreciate it if someone could help me with this program. Basically I have to use Dijkstra algorithm to find shortest path lengths and the shortest path sequence of vertices. I have attached the instructions below. I am also going to attach my code so far, all it does is reads from input file and prints it to the screen.

I would really appreciate it if someone could help me with this

program. Basically I have to use Dijkstra algorithm to find shortest path

import java.io.FileInputStream;

import java.util.Scanner;

public class Main_2 {

static int SV = 0; // source vertex

static int N = 0;

static int M[][];

public static void main(String[] args) {

try {

int i = 0, j = 0; // counters

FileInputStream textFile = new FileInputStream("EXAMPLE(2).txt"); // name of input file must go in here

Scanner scan = new Scanner(textFile);

N = scan.nextInt(); // read in the size

String flush = scan.nextLine(); // gets rid of linefeed

System.out.println(N);

M = new int[N][N]; // instantiates array

// this loop reads in matrix from input file

String line;

while (i

j = 0;

String delim = " ";

String tokens[] = line.split(delim);

for (String a : tokens) {

M[i][j] = Integer.parseInt(a);

j++;

}

i++;

}

if (i > N)

;

SV = scan.nextInt();

} catch (Exception e) {

e.printStackTrace();

}

printMatrix(M);

System.out.println(SV);

}

public static void printMatrix(int[][] Matrix) {

for (int i = 0; i

for (int j = 0; j

System.out.print(Matrix[i][j]);

System.out.print(" ");

}

System.out.println();

}

}

}

f the assignment, write a program that will compute the shortess pth from one source vertex to all other vertices in a and the shortest paths themselves must be computed The graph is a simple undirected weighted graph. The Dijkstra's algorithm must be used. The input to the program is s ile containing the graph. The input file contains the adjacency matrix representing the graph The file contains the size of the matrix at the top and the source vertex at the bottom The output of the program is a file containing the shortest paths from the source vertex to all other vertices. The output file contains the shortest path lengths and the shorest th sequence of vertices graph. Both the path distances Run your program with the given test graphs and compute the shortest paths. Submit the results. average run times to compute the shortest paths from a single vertex to all other vertices. To do this, create large random adjacency matrices of size 100, 200, 500, 1000 with edge weights between Also run your program with large graphs and measure the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!