Question: Java (I use Eclipse): Implement the bfs(int s) function. The program should return an integer array that records the minimum distance between every node to

Java (I use Eclipse):

Implement the bfs(int s) function. The program should return an integer array that records the minimum distance between every node to the source s.

Below is the skeleton to modify for the above question/solution.

Please make sure the program works. A screen shot of the working program and code will be helpful!

Thank you.

public class Graph { public int n; //number of vertice public int[][] A; //the adjacency matrix public Graph () { n = 0; A = null; } public Graph (int _n, int[][] _A) { this.n = _n; this.A = _A; } public int prim (int r) { }

/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int n = 9; int A[][] = { {0, 4, 0, 0, 0, 0, 0, 8, 0}, {4, 0, 8, 0, 0, 0, 0, 11, 0}, {0, 8, 0, 7, 0, 4, 0, 0, 2}, {0, 0, 7, 0, 9, 14, 0, 0, 0}, {0, 0, 0, 9, 0, 10, 0, 0, 0}, {0, 0, 4, 14, 10, 0, 2, 0, 0}, {0, 0, 0, 0, 0, 2, 0, 1, 6}, {8, 11, 0, 0, 0, 0, 1, 0, 7}, {0, 0, 2, 0, 0, 0, 6, 7, 0} }; Graph g = new Graph(n, A); System.out.println(g.prim(0)); }

}

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!