Question 21
Question 22
D = 2 for i = 1 to n do for j = i to n do for k = j + 1 to n do D = D * 3
Question 23
Consider the following C-function:
double foo (int n){
int i;
double sum;
if (n = = 0) return 1.0;
else{
sum = 0.0;
for (i = 0; i < n; i++)
sum += foo (i);
return sum;
}
}
The space complexity of the above function is:
Question 24
double foo (int n)
{
int i;
double sum;
if (n = = 0) return 1.0;
else
{
sum = 0.0;
for (i = 0; i < n; i++)
sum += foo (i);
return sum;
}
}
Question 25
Question 26
counter = 0;
for (i = 1; i < = n; i++)
{
if (A[i] == 1)
counter++;
else {
f(counter);
counter = 0;
}
}
Question 27
T(1) = 1 T(n) = 2T(n - 1) + n, n ≥ 2evaluates to a. 2n + 1- n - 2 b. 2n - n c. 2n + 1 - 2n - 2 d. 2n + n
Question 28
1. (n + k)m = Θ(nm), where k and m are constants 2. 2n + 1 = O(2n) 3. 22n + 1 = O(2n)Which of these claims are correct ?
Question 29
Question 30
Consider the following C function.
int fun1 (int n)
{
int i, j, k, p, q = 0;
for (i = 1; i < n; ++i)
{
p = 0;
for (j = n; j > 1; j = j/2)
++p;
for (k = 1; k < p; k = k*2)
++q;
}
return q;
}
Which one of the following is the time complexity for function fun1?
There are 118 questions to complete.