Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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 End

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

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions

Question

Was there an effort to involve the appropriate people?

Answered: 1 week ago

Question

18. If you have power, then people will dislike and fear you.

Answered: 1 week ago