Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

YOU CAN JUST WRITE THE FIRST FUNCTION(3.1bfs) IMPORTANT: C++ question. 3.1 BFS.

ID: 3699527 • Letter: Y

Question

YOU CAN JUST WRITE THE FIRST FUNCTION(3.1bfs)

IMPORTANT: C++ question.

3.1 BFS. Write a method that prints the vertices in a graph visited in a breadth-first search (BFS) and the verntex with the maximum number of adjacent nodes. void Graph::findNodewithMaximumAdjacent (string); The function should print the BFS sequence and the node that has the maximum number of adjacent nodes. The argument of the function is the starting point of BF Example. For the following graph, 10 25 35 40 The expected output by calling findNodewithMaximumAdjacent ("10") should be 10 25 35 40 25 The first line prints out the BFS traversal sequence, while the second line prints out the node(s) that has maximum number of adjacent nodes. When multiple nodes have same number of maximum number of adjacent nodes, print out all nodes Hint. Use BFS algorithm to traverse the graph, while keep track of number of adjacent nodes for each node.

Explanation / Answer

/*If you have any query do comment in the comment section else like the solution*/

void Graph::findNodeWithMaximumAdjacent(string s)
{
bool *visited = new bool[V];
for(int i = 0; i < V; i++)
visited[i] = false;
queue<string> q;
visited[s] = true;
q.push(s);
list<int>::iterator it;
string node;
int maxm=0;
while(!q.empty())
{
s = q.front();
cout << s << " ";
q.pop();
int count=0;
for (it=adj[s].begin();it!=adj[s].end();it++)
{
count++;
if (!visited[*i])
{
visited[*i]=true;
q.push(*i);
}
}
if(count>maxm)
{
maxm=count;
node=s;
}
}
}