MULTIPLE CHOICE QUESTIONS ANSWERS part 2
MULTIPLE CHOICE QUESTIONS ANSWERS part 2
1. Which is the most appropriate definition for recursion?
a) A function that calls itself
b) A function execution instance that calls another
execution instance of the same function
c) A class method that calls
another class method
d) An in-built method that is
automatically called
2. Only problems that are recursively defined can be solved using
recursion.
a)True
b) False
3. Which of these is false about recursion?
a) Recursive function can be
replaced by a non-recursive function
b) Recursive functions usually
take more memory space than non-recursive function
c) Recursive functions run faster than non-recursive
function
d) Recursion makes programs
easier to understand
4. Fill in the line of the following Python code for calculating the
factorial of a number.
def fact(num):
if num == 0:
return 1
else:
return _____________________
a) num*fact(num-1)
b) (num-1)*(num-2)
c) num*(num-1)
d) fact(num)*fact(num-1)
5. What will be the output of the following Python code?
def test(i,j):
if(i==0):
return j
else:
return test(i-1,i+j)
print(test(4,7))
a) 13
b) 7
c) Infinite loop
d) 17
6. What is tail recursion?
a) A recursive function that has
two base cases
b) A function where the recursive
functions leads to an infinite loop
c) A recursive function where the
function doesn’t return anything and just prints the values
d) A function where the recursive call is the last thing
executed by the function
7. Which of the following statements is false about recursion?
a) Every recursive function must
have a base case
b) Infinite recursion can occur
if the base case isn’t properly mentioned
c) A recursive function makes the
code easier to understand
d) Every recursive function must have a return value
8. What will be the output of the following Python code?
def fun(n):
if (n > 100):
return n - 5
return fun(fun(n+11));
print(fun(45))
a) 50
b) 100
c) 74
d) Infinite loop
9. Recursion and iteration are the same programming approach.
a)True
b) False
10. What happens if the base condition isn’t defined in recursive
programs?
a) Program gets into an infinite loop
b) Program runs once
c) Program runs n number of times
where n is the argument given to the function
d) An exception is thrown
11. Which of these is not true about recursion?
a) Making the code look clean
b) A complex task can be broken
into sub-problems
c) Recursive calls take up less memory
d) Sequence generation is easier
than a nested iteration
12. Which of these is not true about recursion?
a) It’s easier to code some
real-world problems using recursion than non-recursive equivalent
b) Recursive functions are easy to debug
c) Recursive calls take up a lot
of memory
d) Programs using recursion take
longer time than their non-recursive equivalent
13. What will be the output of the following Python code?
def a(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return a(n-1)+a(n-2)
for i in range(0,4):
print(a(i),end=" ")
a) 0 1 2 3
b) An exception is thrown
c) 0 1 1 2 3
d) 0 1 1 2
14. Suppose the first fibonnaci number is 0 and the second is 1. What
is the sixth
fibonnaci number?
a) 5
b) 6
c) 7
d) 8
15. Which of the following is not a fibonnaci number?
a) 8
b) 21
c) 55
d) 14
16. Which of the following option is wrong?
a) Fibonacci number can be
calculated by using Dynamic programming
b) Fibonacci number can be
calculated by using Recursion method
c) Fibonacci number can be
calculated by using Iteration method
d) No method is defined to calculate Fibonacci number.
17. Which of the following recurrence relations can be used to find the
nth fibonacci
number?
a) F(n) = F(n) + F(n – 1)
b) F(n) = F(n) + F(n + 1)
c) F(n) = F(n – 1)
d) F(n) = F(n – 1) + F(n – 2)
18. How many times will the function fibo() be called when the
following code is executed?
int fibo(int n){
if(n == 1)
return 0;
else if(n == 2)
return 1;
return fibo(n - 1) + fibo(n -
2);}int main(){
int n = 5;
int ans = fibo(n);
printf("%d",ans);
return 0;}
a) 5
b) 6
c) 8
d) 9\
19. What is the output of the following code?
int fibo(int n){
if(n == 1)
return 0;
else if(n == 2)
return 1;
return fibo(n - 1) + fibo(n -
2);}int main(){
int n = 10;
int ans = fibo(n);
printf("%d",ans);
return 0;}
a) 21
b) 34
c) 55
d) 13
20. What is the output of the following code?
int fibo(int n){
if(n == 1)
return 0;
else if(n == 2)
return 1;
return fibo(n - 1) + fibo(n -
2);}int main(){
int n = 5;
int ans = fibo(n);
printf("%d",ans);
return 0;}
a) 1
b) 2
c) 3
d) 5
21. What is the objective of tower of hanoi puzzle?
a) To move all disks to some other rod by following rules
b) To divide the disks equally
among the three rods by following rules
c) To move all disks to some
other rod in random order
d) To divide the disks equally
among three rods in random order
22. Which of the following is NOT a rule of tower of hanoi puzzle?
a) No disk should be placed over
a smaller disk
b) Disk can only be moved if it
is the uppermost disk of the stack
c) No disk should be placed over a larger disk
d) Only one disk can be moved at
a time
23. The time complexity of the solution tower of hanoi problem using recursion
is _________
a) O(n2)
b) O(2n)
c) O(n log n)
d) O(n)
24. Recurrence equation formed for the tower of hanoi problem is given
by _________
a) T(n) = 2T(n-1)+n
b) T(n) = 2T(n/2)+c
c) T(n) = 2T(n-1)+c
d) T(n) = 2T(n/2)+n
25. Minimum number of moves required to solve a tower of hanoi problem
with n disks is
__________
a) 2n
b) 2n-1
c) n2
d) n2-1
26. Space complexity of recursive solution of tower of hanoi puzzle is
________
a) O(1)
b) O(n)
c) O(log n)
d) O(n log n)
27. Recursive solution of tower of hanoi problem is an example of which
of the
following algorithm?
a) Dynamic programming
b) Backtracking
c) Greedy algorithm
d) Divide and conquer
28. Tower of hanoi problem can be solved iteratively.
a) True
b) False
29. Minimum time required to solve tower of hanoi puzzle with 4 disks
assuming one
move takes 2 seconds, will be __________
a) 15 seconds
b) 30 seconds
c) 16 seconds
d) 32 seconds