Asymptotic Notation · Algorithms
40 questions · asked in 21 of 27 years (2000–2026)
MCQ 37 · MSQ 2 · NAT 11-mark 27 · 2-mark 13
Questions 21–25 of 40
Answer: (C)
Put . This gives: .
- k = 5: is ? No
- k = 6: is ? Yes
Answer: 6
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)
Answer: (A)
if is even, and if is odd.
Take the remainder mod after every multiplication, so all numbers stay below . Each step needs one squaring, plus one more multiplication when is odd, and then the exponent is cut to . So the number of multiplications satisfies , with .
The exponent halves at most times, so .
This cannot be improved: one multiplication at most doubles the exponent already reached, so reaching needs at least multiplications. So is the tightest bound among the options.
Answer: (A)
Keep practising