c++
1. Consider the following 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) How many asterisks will print with this call: quiz(0);
3. In the linked list implementation of the queue class, where should the push member function place the new entry on the linked list?
5. Which of the following problems would be best solved with a breadth-first search?
|
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.