Recursion and Applications # MCQs Practice set

Q.1 What is recursion in computer science?

A function calling itself
A function calling another function
A loop that runs indefinitely
A conditional statement
Explanation - Recursion occurs when a function calls itself directly or indirectly to solve a problem by breaking it into smaller instances of the same problem.
Correct answer is: A function calling itself

Q.2 Which of the following is a base case in recursion?

The case where the function calls itself
The stopping condition that prevents infinite recursion
The first line of the function
The last statement in a loop
Explanation - A base case is a condition under which the recursive function stops calling itself, preventing infinite recursion.
Correct answer is: The stopping condition that prevents infinite recursion

Q.3 What is the output of a recursive function without a base case?

It terminates normally
It may result in a stack overflow
It produces zero output
It produces random output
Explanation - Without a base case, recursion continues indefinitely, eventually exceeding the call stack limit and causing a stack overflow.
Correct answer is: It may result in a stack overflow

Q.4 Which of the following problems is commonly solved using recursion?

Sorting algorithms like QuickSort and MergeSort
Printing numbers from 1 to 10 using a loop
Adding two numbers directly
Reading input from a file
Explanation - Many divide-and-conquer algorithms such as QuickSort and MergeSort use recursion to solve smaller subproblems.
Correct answer is: Sorting algorithms like QuickSort and MergeSort

Q.5 In recursion, what is meant by 'recursive case'?

The case where recursion terminates
The case where the function continues to call itself
The case where function returns 0
The case where iteration is used instead
Explanation - The recursive case defines how a problem is broken down into smaller instances and ensures that the function continues recursion until reaching the base case.
Correct answer is: The case where the function continues to call itself

Q.6 Which data structure is primarily used to store recursive function calls?

Queue
Stack
Linked List
Array
Explanation - Each recursive call is stored on the call stack. When a function completes, it is popped off the stack.
Correct answer is: Stack

Q.7 Factorial of a number n (n!) can be computed recursively. What is the base case?

n = 1
n = 0
n < 0
n > 1
Explanation - The factorial of 0 is 1. This serves as the base case to stop recursion for factorial computation.
Correct answer is: n = 0

Q.8 What will be the output of a recursive Fibonacci function for n = 5?

3
5
8
2
Explanation - The Fibonacci sequence is 0,1,1,2,3,5... The 5th Fibonacci number is 5.
Correct answer is: 5

Q.9 Which of the following is a disadvantage of recursion?

Easy to implement complex problems
Requires more memory due to call stack
Simplifies code readability
Can be converted to iteration
Explanation - Each recursive call consumes memory on the call stack, which can lead to stack overflow for deep recursion.
Correct answer is: Requires more memory due to call stack

Q.10 Tail recursion is a type of recursion where:

The recursive call is the last operation in the function
The recursive call is the first operation in the function
The recursion has multiple base cases
There is no base case
Explanation - In tail recursion, the function returns the result of the recursive call directly, allowing some languages to optimize memory usage.
Correct answer is: The recursive call is the last operation in the function

Q.11 Which of the following is true about indirect recursion?

Function calls itself directly
Function calls another function which calls the first function
Function does not call any other function
Function calls itself multiple times in a loop
Explanation - Indirect recursion occurs when two or more functions call each other in a cycle.
Correct answer is: Function calls another function which calls the first function

Q.12 What is the time complexity of recursive Fibonacci function (naive implementation)?

O(n)
O(n^2)
O(2^n)
O(log n)
Explanation - Naive recursive Fibonacci calculation repeatedly solves the same subproblems, leading to exponential time complexity O(2^n).
Correct answer is: O(2^n)

Q.13 Which of the following is an example of recursion in real-life?

Russian dolls
Reading a book
Writing a letter
Boiling water
Explanation - Recursion can be illustrated by objects contained within similar objects, like Russian dolls inside each other.
Correct answer is: Russian dolls

Q.14 What happens if the base case is incorrect or unreachable?

Recursion stops normally
Infinite recursion occurs
Function returns None
Function throws a compile-time error
Explanation - If the base case is never reached, recursion continues indefinitely until a stack overflow occurs.
Correct answer is: Infinite recursion occurs

Q.15 Which algorithm commonly uses recursion for tree traversal?

Binary Search Tree traversal
Bubble Sort
Linear Search
Insertion Sort
Explanation - Recursive traversal like inorder, preorder, and postorder are standard methods for trees.
Correct answer is: Binary Search Tree traversal

Q.16 Which of the following best describes mutual recursion?

Function calls itself directly multiple times
Two functions call each other in a cycle
Function calls itself once
Function has multiple base cases
Explanation - Mutual recursion occurs when functions call each other in a circular manner, relying on each other to reach base cases.
Correct answer is: Two functions call each other in a cycle

Q.17 What is a key benefit of using recursion?

Reduces memory usage in all cases
Simplifies code for problems that can be divided into similar subproblems
Always faster than iteration
Avoids use of the stack
Explanation - Recursion simplifies code readability and implementation for problems like divide-and-conquer and tree traversals.
Correct answer is: Simplifies code for problems that can be divided into similar subproblems

Q.18 In which scenario should recursion be avoided?

When problem can be solved iteratively without complexity
When problem is naturally hierarchical
When divide-and-conquer is used
When problem size is unknown
Explanation - Recursion should be avoided when iteration provides a simpler and more memory-efficient solution.
Correct answer is: When problem can be solved iteratively without complexity

Q.19 Which of the following is NOT a property of recursion?

Base case
Recursive case
Infinite loop
Function calls itself
Explanation - Infinite loop is not a property of recursion. Recursion requires a base case to terminate.
Correct answer is: Infinite loop

Q.20 How can tail recursion be optimized in some languages?

Using iterative loops
Using tail call optimization to reuse stack frame
By removing base case
By increasing recursion depth
Explanation - Tail call optimization allows the compiler or interpreter to reuse the current function's stack frame for the recursive call, reducing memory usage.
Correct answer is: Using tail call optimization to reuse stack frame

Q.21 Which sorting algorithm can be implemented using recursion?

Merge Sort
Bubble Sort
Selection Sort
Insertion Sort
Explanation - Merge Sort uses divide-and-conquer strategy and is naturally implemented using recursion.
Correct answer is: Merge Sort

Q.22 In recursion, what is the importance of ensuring the problem size reduces with each call?

To increase execution speed
To ensure that recursion eventually reaches the base case
To use more memory
To simplify the code
Explanation - Reducing the problem size in each recursive call guarantees that the recursion progresses towards termination.
Correct answer is: To ensure that recursion eventually reaches the base case

Q.23 Which of the following is a classic example of recursion in mathematical computation?

Computing factorial of a number
Finding maximum in an array iteratively
Summing numbers using a loop
Searching in a linked list
Explanation - Factorial computation is a standard example where recursion is applied naturally with base and recursive cases.
Correct answer is: Computing factorial of a number