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
What happens if a recursive function does not have a base case?
Without a base case, the function keeps calling itself forever, causing a stack overflow error and crashing the program.
beginner Click to reveal answer
Write the recursive formula for factorial n!
Factorial(n) = n * Factorial(n - 1), with Factorial(0) = 1 as the base case.
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) return?
✗ Incorrect
3! = 3 * 2 * 1 = 6.
Which of these is the correct recursive call in factorial function?
✗ Incorrect
Factorial is calculated by multiplying n with factorial of n-1.
What error occurs if recursion has no base case?
✗ Incorrect
Without base case, recursion calls itself endlessly causing stack overflow.
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.
