Question & Answer: In what order are the vertices visited for a depth-first search that starts at v0?…..

c++

1. Consider the following graph:

graph

In what order are the vertices visited for a depth-first search that starts at v0?

0, 1, 3, 5, 6, 4, 2
0, 1, 3, 6, 5, 4,
0, 2, 1, 3, 5, 6

0, 4, 1, 6

2. Consider the following recursive function:

void quiz(int i)
{
if (i > 1)
{
quiz(i / 2);
quiz(i / 2);
}
cout << “*”;
}

How many asterisks will print with this call:

quiz(0);

0
1

3. In the linked list implementation of the queue class, where should the push member function place the new entry on the linked list?

At the head
Either the head or the tail
In sorted order
At the tail

4. Consider the following function. How would the output that is generated with the call test_a(4) be

different if the cout line were listed after the recursive call in this function?
void test_a(int n)
{
cout << n << ” “;
if (n>0)
test_a(n-2);
}

The integers would print in descending order instead of in ascending order.
The recursive call would never execute because the base case would be true immediately.
There would be no difference in the output of this function.
The integers would print in ascending order instead of in descending order

5. Which of the following problems would be best solved with a breadth-first search?

You need to find the closest node to node x that stores a value greater than 10.
You need to find a valid path from one node to the next through a maze graph.
You need to discover if there is a cycle in a graph.
None of these

6. Which of the following statements regarding binary trees are true?

Every non-empty tree has exactly one root node.
Every node has at most two children.
Every binary tree has at least one node.
Every non-root node has exactly one parent.

7. A queue should not be built with an array. A circular array would be a better implementation choice for this data structure.

True
False

Expert Answer

 

Solution :

2:

for function call quiz(0) , value of i = 0
hence if(i>1){….} block will not be executed as i = 0 and i is not greter than 1.

hence ‘*’ is printed only once.

3:

Answer : at the tail.

since queue is a data structure when from head we remove elements and we add elements to tail.
the new element will be added to tail.

4:

for current code output will be : 4 2 0

if cout line is at the end then numbers will be printed in reverse order : 0 2 4.

hence answer => option D : the integers would print in ascending order instead of decending order.

5:

answer : A
-to find closest node, it is good to check neighbours first. hence bfs is better for it.
– cycle can be detected using bfs too.[DFS is more convinient for it but bfs can be used too.]

6:

Answer A,B,D

every binary tree has at least one node is not true. Binary tree can be empty too.

7:

true.
circular array allows a better implementation of queue.

Still stressed from student homework?
Get quality assistance from academic writers!