Q. In a recursive function, what is the purpose of the return statement?
-
A.
To terminate the program
-
B.
To return control to the caller
-
C.
To call the function again
-
D.
To print the output
Solution
The return statement is used to return control to the caller along with any computed value.
Correct Answer:
B
— To return control to the caller
Learn More →
Q. What happens if a recursive function does not have a base case?
-
A.
It will run indefinitely
-
B.
It will return a default value
-
C.
It will throw an error
-
D.
It will terminate successfully
Solution
If a recursive function does not have a base case, it will run indefinitely, leading to a stack overflow.
Correct Answer:
A
— It will run indefinitely
Learn More →
Q. What is tail recursion?
-
A.
Recursion where the last operation is a recursive call
-
B.
Recursion that does not use any stack
-
C.
Recursion that calls itself multiple times
-
D.
Recursion that has no base case
Solution
Tail recursion is when the last operation of a function is a recursive call, allowing for optimization.
Correct Answer:
A
— Recursion where the last operation is a recursive call
Learn More →
Q. What is the time complexity of a recursive function that divides the problem size by half at each step?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(2^n)
Solution
The time complexity is O(log n) because the problem size is halved at each recursive call.
Correct Answer:
B
— O(log n)
Learn More →
Q. Which of the following is a base case in a recursive function?
-
A.
The case that leads to infinite recursion
-
B.
The case that stops the recursion
-
C.
The case that calls the function again
-
D.
The case that doubles the input size
Solution
A base case is the condition under which the recursion stops, preventing infinite recursion.
Correct Answer:
B
— The case that stops the recursion
Learn More →
Q. Which of the following is an example of a problem that can be solved using divide and conquer?
-
A.
Binary search
-
B.
Fibonacci sequence
-
C.
Linear search
-
D.
Bubble sort
Solution
Binary search is an example of a divide and conquer algorithm, as it divides the search space in half.
Correct Answer:
A
— Binary search
Learn More →
Q. Which of the following is true about recursive algorithms?
-
A.
They always run faster than iterative algorithms
-
B.
They can be less memory efficient due to call stack
-
C.
They cannot be used for sorting
-
D.
They are always easier to understand
Solution
Recursive algorithms can be less memory efficient due to the overhead of maintaining the call stack.
Correct Answer:
B
— They can be less memory efficient due to call stack
Learn More →
Q. Which of the following problems can be solved using recursion?
-
A.
Finding the maximum element in an array
-
B.
Calculating the factorial of a number
-
C.
Sorting an array
-
D.
All of the above
Solution
All of the above problems can be solved using recursion.
Correct Answer:
D
— All of the above
Learn More →
Showing 1 to 8 of 8 (1 Pages)