Algorithm Design & Analysis Questions With
Answers
Question 1.
Binary Search
Correct Answer: An ordered list is divided in 2 with each comparison.
Question 2.
Complexity of the following (Fibonacci Func.): int fibRec(n){
if ( n <= 1){
return n;
else
return fibRec(n-1) + fibRec(n-2));
Correct Answer: O(2^n)
Question 3.
Name an example of O(N^3) complexity
Correct Answer: Matrix multiplication
Question 4.
Order the following in terms of quickest growth Linear Time : _________
Logarithmic Time : _________
Constant Time: _________
Quadratic Time : _________
Correct Answer: Linear Time - O(n) : 2 Logarithmic Time O(log n) : 3
Constant Time - O(1) : 4 Quadratic Time - O(n2) : 1
Question 5.
Order the following in terms of quickest growth: O(1) : _________
O(2^n) : _________
O(n^2) : _________
O(n) : _________
O(nlogn) : _________
O(n!) : _________
Correct Answer: O(1) - 6 O(2^n) - 2 O(n^2) - 3 O(n) - 5 O(nlogn) - 4 O(n!) - 1
Question 6.
Which of the followings is true?
a)Θ(f) - At the rate of f
b)O(f) - At most as fast as f
c)Ω(f) - At least as fast as f
d)Θ(f), O(f), Ω(f) gives us asymptotic behavior
e)All of the above
Correct Answer: e)All of the above
,Question 7.
What does it mean when we say that an algorithm X is asymptotically more efficient than
Y?
a)X will always be a better choice for small inputs
b)X will always be a better choice for large inputs
c)Y will always be a better choice for small inputs
d)X will always be a better choice for all inputs
Correct Answer: b)X will always be a better choice for large inputs
Question 8.
the rate of Θ(f)
Correct Answer: At the rate of f
Question 9.
the rate of O(f)
Correct Answer: At most as fast as f
Question 10.
the rate of Ω(f)
Correct Answer: At least as fast as f
Question 11.
What is the asymptotic complexity of n + n^2 + 2n + n^4 ?
Correct Answer: O(n^2)
Question 12.
What is the asymptotic complexity of 3n^2+ 10nlogn + 1000n + 4logn + 9999?
Correct Answer: O(n^2)
Question 13.
What is the asymptotic complexity of n^3 + n^2 + n + log n?
Correct Answer: O(n^2)
Question 14.
•What is the asymptotic complexity of n + 2^n + 3^n + n^4?
Correct Answer: O(2^n)
Question 15.
What is the asymptotic complexity of nlogn + logn + n?
Correct Answer: O(nlogn)
Question 16.
What is the asymptotic complexity of n! + n3 + 5n?
Correct Answer: O(n!)
Answers
Question 1.
Binary Search
Correct Answer: An ordered list is divided in 2 with each comparison.
Question 2.
Complexity of the following (Fibonacci Func.): int fibRec(n){
if ( n <= 1){
return n;
else
return fibRec(n-1) + fibRec(n-2));
Correct Answer: O(2^n)
Question 3.
Name an example of O(N^3) complexity
Correct Answer: Matrix multiplication
Question 4.
Order the following in terms of quickest growth Linear Time : _________
Logarithmic Time : _________
Constant Time: _________
Quadratic Time : _________
Correct Answer: Linear Time - O(n) : 2 Logarithmic Time O(log n) : 3
Constant Time - O(1) : 4 Quadratic Time - O(n2) : 1
Question 5.
Order the following in terms of quickest growth: O(1) : _________
O(2^n) : _________
O(n^2) : _________
O(n) : _________
O(nlogn) : _________
O(n!) : _________
Correct Answer: O(1) - 6 O(2^n) - 2 O(n^2) - 3 O(n) - 5 O(nlogn) - 4 O(n!) - 1
Question 6.
Which of the followings is true?
a)Θ(f) - At the rate of f
b)O(f) - At most as fast as f
c)Ω(f) - At least as fast as f
d)Θ(f), O(f), Ω(f) gives us asymptotic behavior
e)All of the above
Correct Answer: e)All of the above
,Question 7.
What does it mean when we say that an algorithm X is asymptotically more efficient than
Y?
a)X will always be a better choice for small inputs
b)X will always be a better choice for large inputs
c)Y will always be a better choice for small inputs
d)X will always be a better choice for all inputs
Correct Answer: b)X will always be a better choice for large inputs
Question 8.
the rate of Θ(f)
Correct Answer: At the rate of f
Question 9.
the rate of O(f)
Correct Answer: At most as fast as f
Question 10.
the rate of Ω(f)
Correct Answer: At least as fast as f
Question 11.
What is the asymptotic complexity of n + n^2 + 2n + n^4 ?
Correct Answer: O(n^2)
Question 12.
What is the asymptotic complexity of 3n^2+ 10nlogn + 1000n + 4logn + 9999?
Correct Answer: O(n^2)
Question 13.
What is the asymptotic complexity of n^3 + n^2 + n + log n?
Correct Answer: O(n^2)
Question 14.
•What is the asymptotic complexity of n + 2^n + 3^n + n^4?
Correct Answer: O(2^n)
Question 15.
What is the asymptotic complexity of nlogn + logn + n?
Correct Answer: O(nlogn)
Question 16.
What is the asymptotic complexity of n! + n3 + 5n?
Correct Answer: O(n!)