Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm having trouble wiht this program. Below is the skeleton code as well as the psudocode. (https://docs. oracle.com/javase/7/docs/api/java/util/LinkedList.html). More tutorials can be found https://www.javatpoint.com/java-linkedlist and

I'm having trouble wiht this program. Below is the skeleton code as well as the psudocode.

image text in transcribed

image text in transcribed

(https://docs. oracle.com/javase/7/docs/api/java/util/LinkedList.html). More tutorials can be found https://www.javatpoint.com/java-linkedlist and http://www.javadb.com/using-a-queue-or-linkedlist/.

//package graph;

import ds.Queue;

public class Graph {

public int n; /umber of vertice

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

private final int WHITE = 2;

private final int GRAY = 3;

private final int BLACK = 4;

public Graph () {

n = 0;

A = null;

}

public Graph (int _n, int[][] _A) {

this.n = _n;

this.A = _A;

}

/*

* Input: s denotes the index of the source node

* Output: the array dist, where dist[i] is the distance between the i-th node to s

*/

public int[] bfs (int s) {

}

public void print_array (int[] array) {

for (int i = 0; i

System.out.println(i + ": " + array[i]);

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

int n = 8;

int[][] A =

{{0, 1, 0, 0, 1, 0, 0, 0},

{1, 0, 0, 0, 0, 1, 0, 0},

{0, 0, 0, 1, 0, 1, 1, 0},

{0, 0, 1, 0, 0, 0, 1, 1},

{1, 0, 0, 0, 0, 0, 0, 0},

{0, 1, 1, 0, 0, 0, 1, 0},

{0, 0, 1, 1, 0, 1, 0, 1},

{0, 0, 0, 1, 0, 0, 1, 0}};

Graph g = new Graph(n, A);

g.print_array(g.bfs(1));

}

}

1 Problem Description Instructions. You are provided one skeleton program named Graph.java. The source files are available on Canvas in a folder named HW7. Please modify the skeleton code to solve the following tasks. . Task 1 (100 pts). Implement the bfs(int s) function as discussed in Lecture 15. - Note: You should return an integer array that records the mini- ode to the mum distance between every n - Hint 1: The colors have been defined in the class for you to use - Hint 2: In the matrix-adjacency representation, each node is just source s an integer. So you cannot do this u.colorWHITE for a node u. Instead, I suggest you to create an integer array to rep- resent the colors of the nodes, another array to represent the distance d for the nodes You can ignore the parent r in your code To use the Enqueue and Dequeue function, you may use - Hint 3: -Hint 4: your previous implementation of Queue in HW3. Or you can use the add) and remove) function of Java LinkedList (https://docs oracle.com/javase/7/docs/api/java/util/LinkedList.html). More tutorials can be found https://www.javatpoint.com/java-linkedlist and http://www.javadb.com/using-a-queue-or-linkedlist/ . Task 2 (Extra Credit 100 pts). Implement the DFS) and DFS.Visit0) functions as discussed in Lecture 16 1 Problem Description Instructions. You are provided one skeleton program named Graph.java. The source files are available on Canvas in a folder named HW7. Please modify the skeleton code to solve the following tasks. . Task 1 (100 pts). Implement the bfs(int s) function as discussed in Lecture 15. - Note: You should return an integer array that records the mini- ode to the mum distance between every n - Hint 1: The colors have been defined in the class for you to use - Hint 2: In the matrix-adjacency representation, each node is just source s an integer. So you cannot do this u.colorWHITE for a node u. Instead, I suggest you to create an integer array to rep- resent the colors of the nodes, another array to represent the distance d for the nodes You can ignore the parent r in your code To use the Enqueue and Dequeue function, you may use - Hint 3: -Hint 4: your previous implementation of Queue in HW3. Or you can use the add) and remove) function of Java LinkedList (https://docs oracle.com/javase/7/docs/api/java/util/LinkedList.html). More tutorials can be found https://www.javatpoint.com/java-linkedlist and http://www.javadb.com/using-a-queue-or-linkedlist/ . Task 2 (Extra Credit 100 pts). Implement the DFS) and DFS.Visit0) functions as discussed in Lecture 16

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

JDBC Database Programming With J2ee

Authors: Art Taylor

1st Edition

0130453234, 978-0130453235

More Books

Students also viewed these Databases questions

Question

=+What can we learn about the PVA data from this decision tree?

Answered: 1 week ago

Question

2. Describe why we form relationships

Answered: 1 week ago

Question

5. Outline the predictable stages of most relationships

Answered: 1 week ago