Recall & Review
beginner Click to reveal answer
What is recursion in programming?
Recursion is when a function calls itself to solve smaller parts of a problem until it reaches a simple case it can solve directly.
beginner Click to reveal answer
What is the base case in a recursive factorial function?
The base case is when the input number is 0 or 1, and the factorial is 1. This stops the recursion from continuing forever.
intermediate Click to reveal answer
Explain how factorial of 4 is calculated using recursion.
Factorial(4) calls Factorial(3), which calls Factorial(2), which calls Factorial(1). Factorial(1) returns 1. Then results multiply back: 1 * 2 = 2, 2 * 3 = 6, 6 * 4 = 24.
beginner Click to reveal answer
Write the recursive formula for factorial.
factorial(n) = n * factorial(n - 1), with factorial(0) = 1 as the base case.
intermediate Click to reveal answer
What happens if the base case is missing in a recursive factorial function?
Without a base case, the function calls itself forever, causing a stack overflow error and crashing the program.
What is the factorial of 0?
✗ Incorrect
By definition, factorial of 0 is 1.
In recursion, what stops the function from calling itself infinitely?
✗ Incorrect
The base case provides a condition to stop recursion.
What does factorial(3) equal?
✗ Incorrect
3! = 3 * 2 * 1 = 6.
Which of these is the correct recursive call for factorial(n)?
✗ Incorrect
The factorial function multiplies n by factorial of n-1.
What error occurs if recursion never reaches a base case?
✗ Incorrect
Infinite recursion causes stack overflow error.
Explain how recursion works in calculating factorial with an example.
Think about how factorial(4) breaks down into smaller factorial calls.
You got /4 concepts.
Describe the importance of the base case in a recursive factorial function.
What happens if the base case is missing?
You got /4 concepts.
