Recursion
In a recursive method, what is the primary role of the base case?
To make the code run faster.
To call the method again with a modified input.
To prevent the method from running indefinitely by providing a stopping condition.
To handle errors that may occur during the recursive calls.
Which of the following best describes a recursive call?
A method calling another method in the same class.
A method calling itself with a modified version of the original problem.
A method that does not have a return statement.
A method that only contains a base case.
Consider the following recursive method:
java
public int mystery(int n) {
if (n == 0) {
return 0;
} else {
return n + mystery(n - 1);
}
}
What is the output of mystery(3)
?
0
3
6
10
What is a potential drawback of using recursion compared to iteration?
Recursive code is always more efficient.
Recursive code can lead to stack overflow errors if the base case is not reached or defined incorrectly.
Recursive code is easier to read and understand.
Recursive code always uses less memory.
Given an array arr = {1, 2, 3, 4, 5}
, what would be the base case for a recursive method designed to print each element of the array?
When the array is empty.
When the index is 0.
When the index is equal to the length of the array.
When the array contains only one element.
Which of the following is a disadvantage of using recursion to traverse an array compared to using a loop?
Recursion is generally faster.
Recursion requires less memory.
Recursion can lead to stack overflow errors for large arrays.
Recursion is simpler to implement.
In a recursive binary search, what condition must be met for the algorithm to work correctly?
The array must be sorted.
The array must contain only positive numbers.
The array must not contain duplicate values.
The array must be of even length.

How are we doing?
Give us your feedback and let us know how we can improve
Given a sorted array arr = {2, 4, 6, 8, 10}
, what would be the next step in a recursive binary search to find the target value 4?
Search the subarray {6, 8, 10}.
Search the subarray {2, 4}.
Search the subarray {2}.
Search the subarray {2, 4, 6}.
What is the time complexity of a recursive binary search algorithm in the best-case scenario?
In merge sort, what is the primary purpose of the 'merge' function?
To divide the array into smaller sub-arrays.
To sort each half of the array independently.
To combine two sorted sub-arrays into a single sorted array.
To find the middle element of the array.