Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am doing a graph matrix in java and currently implementing the Breadth First Traversal The pseudocode is and the code that I currently have
I am doing a graph matrix in java and currently implementing the Breadth First Traversal
The pseudocode is
and the code that I currently have is and I got stuck on the for loop
public void BF(int s) { Queue q = new Queue(); id = 0; for(int v=1; v
q.enQueue(s); while(!q.isEmpty()) {
int v = q.deQueue(); if (visited[v] != 0) { visited[v] = ++id; for (; ; ) { } } }
}
Graph :: BF( Vertex s) Begin Queue a id = 0 for v = 1 to V visited[v] = 0 q.enQueue(s) while (not q.isEmpty()) v=q.deQueue() if (not visited[v]) visited[v] = ++id for each vertex u e adj(v) if (not visited[u]) q.enQueue(u) end for end if end while EndStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started