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 factorial of a number n (n!)?
Factorial of n is the product of all positive integers from 1 to n. For example, 4! = 4 × 3 × 2 × 1 = 24.
beginner Click to reveal answer
What is the base case in the factorial recursion?
The base case is when n equals 0 or 1, and the factorial is 1. This stops the recursion from going forever.
intermediate Click to reveal answer
How does the recursive factorial function calculate factorial(n)?
It multiplies n by factorial(n-1), calling itself with smaller numbers until it reaches the base case.
beginner Click to reveal answer
Why is it important to have a base case in recursion?
Without a base case, the function would call itself forever, causing a crash or error.
What is the factorial of 0?
✗ Incorrect
By definition, factorial of 0 is 1.
In recursion, what stops the function from calling itself endlessly?
✗ Incorrect
The base case tells the function when to stop calling itself.
What does factorial(4) equal?
✗ Incorrect
4! = 4 × 3 × 2 × 1 = 24.
Which of these is a correct recursive call for factorial(n)?
✗ Incorrect
The function calls itself with n-1 to reduce the problem size.
What is the output of factorial(1)?
✗ Incorrect
Factorial of 1 is 1 by definition.
Explain how recursion works in calculating factorial of a number.
Think about how the problem gets smaller each time.
You got /3 concepts.
Describe why a base case is necessary in a recursive factorial function.
What happens if the function never stops calling itself?
You got /3 concepts.
