Question: Please give me the correct JAVA code for this question. Last time, I got an incorrect answer. / * * Lab 1 1 starter code;

Please give me the correct JAVA code for this question. Last time, I got an incorrect answer.
/*
* Lab11 starter code; description in Lab11.pdf.
*/
import java.util.LinkedList;
import java.util.Random;
public class RandomGraph {
public static void main(String[] args){
int n =5; // number of vertices
double p =0.3; // probability that an edge is present
long seed =123; // pseudo-random number generator seed
Random rng = new Random(seed);
Graphm graph = new Graphm(n); // use the adjacency matrix implementation
// create a random graph; each edge present with probability p
for(int i=0;i Q = new LinkedList();
Q.addLast(start);
G.setMark(start,1);
int d =0;
while (Q.size()>0){// Process each vertex on Q
++d;
int v = Q.removeFirst();
PreVisit(G, v); // Take appropriate action
for (int w = G.first(v); w G.n(); w = G.next(v, w))
if (G.getMark(w)==0){// Put neighbors on Q
G.setMark(w, G.getMark(v)+1);
Q.addLast(w);
}
PostVisit(G, v); // Take appropriate action
}
}
static void PreVisit(Graph G, int v){
//System.out.println("");
}
static void PostVisit(Graph G, int v){
//System.out.println("");
}
static void graphTraverse(Graph G){
int v;
for (v =0; v G.n(); v++)
G.setMark(v,0); // Initialize; 0 means "unvisited"
for (v =0; v G.n(); v++){
if (G.getMark(v)==0){
BFS(G, v);
//DFS(G, v);
}
}
}
}
Please give me the correct JAVA code for this

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 Programming Questions!