Identifying the Base Case
In a recursive factorial function where factorial(0) returns 1, what is the role of this base case in the control flow?
- It stops further recursive calls by providing a direct answer for the simplest input.
- It speeds up multiplication using memoization.
- It converts recursion into iteration automatically.
- It increases the stack size to prevent overflow.
- It sorts the intermediate results before returning.
When the Base Case Is Missing
If a recursive function for computing the length of a list never checks for an empty list, what is the most likely outcome at runtime?
- A stack overflow due to infinite recursion.
- A queue overflow due to breadth-first calls.
- A compile-time error because recursion is not allowed.
- Silent termination with a default value.
- Automatic tail-call optimization fixing the issue.
Order of Actions: Before and After the Call
Given a function step(n) that prints 'down' when n u003E 0, then calls step(n-1), and finally prints 'up', what sequence is printed when n is 2?
- down, down, up, up
- down, up, down, up
- up, up, down, down
- down, down, down, up
- up, down, up, down
Stack Space in Linear Recursion
For a linear recursive function that decreases n by 1 until it reaches 0, what is the additional space complexity due to the call stack as a function of n?
- O(n)
- O(1)
- O(log n)
- O(n^2)
- O(nn)
Understanding Tail Recursion
Which statement best describes tail recursion in terms of control flow?
- The recursive call is the final action in the function, so no work remains after it returns.
- The recursive call happens at the start and is called a tale call.
- Tail recursion always runs faster than loops regardless of the language.
- Tail recursion increases the depth of the call stack on purpose.
- Tail recursion means the function calls two tails of the input at once.