Recall & Review
beginner Click to reveal answer
What is the factorial of a number?
The factorial of a number n (written as n!) is the product of all positive integers from 1 up to n. For example, 4! = 4 × 3 × 2 × 1 = 24.
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 n equals 0 or 1, and the factorial is 1. This stops the recursion from continuing 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 a smaller number until it reaches the base case.
intermediate Click to reveal answer
What happens if a recursive function does not have a base case?
The function will keep calling itself forever, causing a stack overflow error and crashing the program.
What is the factorial of 0?
✗ Incorrect
By definition, 0! is 1.
In a recursive factorial function, what does the function call factorial(n-1) represent?
✗ Incorrect
factorial(n-1) calls the function with a smaller number to break down the problem.
What is the base case for factorial recursion?
✗ Incorrect
The base case is when n is 0 or 1, factorial is 1.
What will happen if the base case is missing in a recursive factorial function?
✗ Incorrect
Without a base case, recursion never stops, causing a crash.
Which of these is the correct recursive formula for factorial?
✗ Incorrect
Factorial multiplies n by factorial of (n-1).
Explain how a recursive function calculates the factorial of a number.
Think about how the function breaks the problem into smaller parts and stops.
You got /4 concepts.
Describe why a base case is important in recursion, especially in factorial calculation.
Without it, the function would never stop calling itself.
You got /4 concepts.
