GATE 2008
185 questions
MCQ 1851-mark 52 · 2-mark 133
Questions 101–105 of 185
a.
b.
c.
d.
e.
Answer: (A)
Polynomial-type functions: a is below d, since . d is below c, since ; a power of grows slower than any positive power of . (For example, at , , while .) So a d c.
Exponential functions: e has base , so it eventually beats every polynomial, including c. And b has the larger base: , so e b.
The order is a, d, c, e, b.
Answer: (A)
int f1(int n)
{
if(n == 0 || n == 1)
return n;
else
return (2*f1(n-1) + 3*f1(n-2));
}
int f2(int n)
{
int i;
int X[N], Y[N], Z[N] ;
X[0] = Y[0] = Z[0] = 0;
X[1] = 1; Y[1] = 2; Z[1] = 3;
for(i = 2; i <= n; i++)
{
X[i] = Y[i-1] + Z[i-2];
Y[i] = 2*X[i];
Z[i] = 3*X[i];
}
return X[n] ;
} The running time of f1(n) and f2(n) areAnswer: (B)
f1 calls itself on and and does a constant amount of other work (the factors and only cost constant time). So , with .
Since , we get , so roughly. Also gives , so roughly (up to constants). So the time is exponential.
More exactly, this is the Fibonacci recurrence and it grows like , with . That is but not exactly , so the in option (B) is loose. Among the options, (B) is the only one that makes f1 exponential.
f2 is a loop that runs from to , that is times. Each pass does a constant number of array operations and no recursive call, because , and are computed once from stored earlier values. So the time is .
So f1 is exponential and f2 is linear.
Answer: (B)
Which of the following statements about the asymptotic behaviour of f(n), g(n), and h(n) is true?
Answer: (D)
h(n): . The exponent grows slower than , so , that is, .
g(n): going from to multiplies by , while only doubles. For the factor beats 2, so keeps growing without bound. So and is not .
Because and is not , is not either. So grows fastest and slowest.
(A) and (B) say , which is false. (C) says , which is false. In (D) both parts are true.
Answer: (D)
evaluates to :
Answer: (A)
Each added term is the same: , and in general . The recursion reaches after levels (with ), so there are such terms.
The last term is .
The Master theorem would give only , which is option (B). But it gives only an asymptotic bound, not the exact value, and the question asks what the recurrence evaluates to. Check: gives and , and . Option (B) would give 4.
Answer: (A)
The value of is
Answer: (C)
- Ends in 1: the first bits can be any valid string, giving strings.
- Ends in 0: the bit before it must be 1, so the string is a valid string of length followed by 10, giving strings.
The two cases share no string and cover all, so .
Start: (0, 1) and (01, 10, 11).
, , .
Answer: (C)