Which of the following is the correct base case for a recursive function that…
2025
Which of the following is the correct base case for a recursive function that computes the factorial of a non-negative integer n, so that the recursion terminates correctly for every valid input (including n = 0)?
- A.
n == 0
- B.
n == 1
- C.
n < 0
- D.
n > 0
Attempted by 491 students.
Show answer & explanation
Correct answer: A
Concept
A recursive function needs a base case: a condition under which it returns a value directly without calling itself. The base case is what stops the recursion. For it to be correct, it must be reached by every valid input as the recursive step shrinks the problem, and it must cover the smallest value in the function's domain.
Application
Factorial is defined on the non-negative integers, with the boundary value 0! = 1. A recursive definition is: factorial(n) = n times factorial(n - 1) for n greater than 0, and the base case returns 1 at the bottom. Trace the shrinking argument:
Each recursive call replaces n with n - 1, so the argument decreases by 1 every step.
Starting from any non-negative n, this descending chain passes through every smaller value and reaches 0.
0 is the smallest value in the domain and its factorial is defined as 1, so returning 1 when n equals 0 is exactly the boundary the definition gives.
With the stop placed at n equal to 0, the call for n = 0 itself also terminates, so the function is total over all non-negative inputs.
Therefore the base case is the condition n equals 0, returning 1.
Cross-check
Verify by hand for n = 3: factorial(3) = 3 times factorial(2) = 3 times 2 times factorial(1) = 3 times 2 times 1 times factorial(0). The last call hits the base case and returns 1, giving 3 times 2 times 1 times 1 = 6, which is 3! as expected. Note that stopping at n equal to 1 instead would never return for the input 0, and a condition like n greater than 0 is true exactly for the cases that must keep recursing, so neither can serve as the stopping rule.