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.
Lab starter code; description in Labpdf
import java.util.LinkedList;
import java.util.Random;
public class RandomGraph
public static void mainString args
int n ; number of vertices
double p ; probability that an edge is present
long seed ; pseudorandom number generator seed
Random rng new Randomseed;
Graphm graph new Graphmn; use the adjacency matrix implementation
create a random graph; each edge present with probability p
forint i;i Q new LinkedList;
QaddLaststart;
GsetMarkstart;
int d ;
while Qsize Process each vertex on Q
d;
int v QremoveFirst;
PreVisitG v; Take appropriate action
for int w Gfirstv; w Gn; w Gnextv w
if GgetMarkw Put neighbors on Q
GsetMarkw GgetMarkv;
QaddLastw;
PostVisitG v; Take appropriate action
static void PreVisitGraph G int v
Systemout.println;
static void PostVisitGraph G int v
Systemout.println;
static void graphTraverseGraph G
int v;
for v ; v Gn; v
GsetMarkv; Initialize; means "unvisited"
for v ; v Gn; v
if GgetMarkv
BFSG v;
DFSG v;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
