Complete the mcq:
1 A queue is modeled on a ____ structure.
LIFO
FIFO
stack
list
2 The function deleteQueue does which of the following?
uses one queue to delete another
removes the back element from the queue
removes the front element from the queue
removes all elements from the queue leaving an empty queue
Refer to the figure above. Which of the following members from the UML diagram removes an element from the front of the queue?
destroyQueue
front
deleteQueue
removeQueue
4 int func2(int m, int n) {
if (n == 0)
return 0;
else
return m + func2(m, n-1);
}
What is the output of func2(, 2)?
2
5
6
5
int func1(int m, int n) {
if (m==n || n==1)
return 1;
else
return func1(m-1,n-1) + n*func1(m-1,n);
}
What precondition must exist in order to prevent the code above from infinite recursion?
m > = 0 and n >= 0
m >= 0 and n >= 1
m >= 1 and n >= 0
m >= 1 and n >= 1
6
int func(int m, int n) {
if (m < n)
return 0;
else
return 1 + func(m-n, n);
}
What is the value of func(-5, 1), based on the code above?
-5
0
1
5
7
Assume there are four functions A, B, C, and D. If function A calls function B, function B calls function C, function C calls function D, and function D calls function A, which of the following functions is indirectly recursive?
A
B
C
D
8
int func1(int m, int n) {
if (m==n || n==1)
return 1;
else
return func1(m-1,n-1) + n*func1(m-1,n);
}
Based on the function above, what is the value of func1(4, 2)?
5
7
9
9
void decToBin(int num, int base)
{
if(num > 0)
{
decToBin(num/base, base);
cout< }
}
Based on the code above, which of the following calls to the function would produce the result 1001?
decToBin(4, 2)
decToBin(2, 4)
decToBin(9, 2)
decToBin(8, 1)
40
int func2(int m, int n) {
if (n == 0)
return 0;
else
return m + func2(m, n-1);
}
What is the limiting condition of the code above?
n >= 0
m > n
m >= 0
n > m