public int mystery(int k, int n)
{
if (n= =k)
return k;
else if (n > k)
return mystery(k, n-k);
else
return mystery(k-n, n);
}
Based on the method defined, what is the value of mystery(6, 8)?
A -
3
B -
4
C -
2
D -
8
4-
Queues are referred to as ____ data structures?
A -
IFOF
B -
FIFO
C -
LIFO
D -
FILO
5-
Recursion has a serious disadvantage of using large amount of memory. Moreover, for
most programming languages, recursion use stack store states of all currently active recursive
calls. The size of a stack may be quite large, but limited. Therefore too deep recursion can result
in ____
A -
Memmory Overflow
B -
Stacks Overflow
C -
Haft Infinity Loop
D -
Out of Memmory
6-
Refer to this binary expression tree.
Choose the algebraic expression stored in the tree
A -
* + / - a b c d e
B -
+ / a b – c * d e
C -
+ / - a b c * d e
D -
– a b / c + * d e
7-
Select INVALID way to calculate the sum of the first n even numbers (that is, 2 + 4 +6
+ … + 2*n)
A -
int sum = 0; for(int i = 1; i<=2*n; i+=1){ if(i % 2 = =0){ sum += i; } }
B -
int sum = 0; int i = 2; while(i%2 = =0 && i<= 2n){ sum += i; }
C -
int sum = 0; for(int i = 1; i<=2*n; i+=1){ if(i / 2 = =0){ sum += i; } }
D -
int sum = 0; for(int i = 1; i<=2*n; i+=1){ sum += i; }
8-
Select value of x after running code segment:
void main( )
{
float a[5] = {5, 4, 3, 2, 1};
float x;
int i;
for (i = 0; i < 5; i++)
a[i] += a[0];
x = a[1] + a[4];
}
A -
100
B -
25
C -
5
D -
125
9-
Select result after running code segment?
int i = 1;
while (i <= 10)
{
Cout << X;
i = i +3;
}