Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please modify the skeleton code to solve the following tasks. package graph; public class Graph2 { public int n; /umber of vertice public int[][] A;//the

Please modify the skeleton code to solve the following tasks.

image text in transcribed

package graph;

public class Graph2 {

public int n; /umber of vertice

public int[][] A;//the adjacency matrix

public Graph2 () {

n = 0;

A = null;

}

public Graph2 (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}

};

Graph2 g = new Graph2(n, A);

System.out.println(g.prim(0));

}

}

Task 1 (100 pts). Implement the prim(int r) function as discussed in Lecture 18. -Note: You should return an integer that indicates the total weight of the minimum spanning tree. Hint 1: W h. If Ai[j]-0, it means there is no edge between the i-th and j-th node If A [i][j] 0, then it means the weight of the edge between the i-th and j-th node. Hint 2: To learn how to use Priority Queue in Java, google Java PriorityQueue API. Also find some tutorials on Java Pri orityQueue to understand it better Hint 3: In order to associate each node with a weight and place it e use an adjacent matrix to represent the grap reate another class. Check ListN- ode.java and LnkedList.java in HW3 t class. o get an exanple of auxiliary Task 1 (100 pts). Implement the prim(int r) function as discussed in Lecture 18. -Note: You should return an integer that indicates the total weight of the minimum spanning tree. Hint 1: W h. If Ai[j]-0, it means there is no edge between the i-th and j-th node If A [i][j] 0, then it means the weight of the edge between the i-th and j-th node. Hint 2: To learn how to use Priority Queue in Java, google Java PriorityQueue API. Also find some tutorials on Java Pri orityQueue to understand it better Hint 3: In order to associate each node with a weight and place it e use an adjacent matrix to represent the grap reate another class. Check ListN- ode.java and LnkedList.java in HW3 t class. o get an exanple of auxiliary

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions

Question

3. What may be the goal of the team?

Answered: 1 week ago

Question

Is how things are said consistent with what is said?

Answered: 1 week ago

Question

Has the priority order been provided by someone else?

Answered: 1 week ago