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?
The factorial of a number n (written as 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
Why do we need a base case in a recursive function?
A base case stops the recursion by providing a simple answer without calling itself again. Without it, the function would call itself forever.
beginner Click to reveal answer
How does the factorial function use recursion?
The factorial function calls itself with a smaller number (n-1) until it reaches 0, then multiplies all results back up to get the final answer.
beginner Click to reveal answer
What is the output of factorial(3) using recursion?
factorial(3) = 3 × factorial(2) = 3 × 2 × factorial(1) = 3 × 2 × 1 = 6
What is the base case for factorial recursion?
✗ Incorrect
The base case for factorial is when n equals 0, factorial(0) is defined as 1.
What does factorial(5) return?
✗ Incorrect
5! = 5 × 4 × 3 × 2 × 1 = 120
What happens if a recursive function has no base case?
✗ Incorrect
Without a base case, recursion never stops and causes a stack overflow error.
Which of these is the recursive call in factorial function?
✗ Incorrect
The factorial function multiplies n by factorial of (n-1).
What is factorial(1)?
✗ Incorrect
factorial(1) is 1 by definition and often used as a base case.
Explain how recursion works in calculating factorial of a number.
Think about how factorial(n) depends on factorial(n-1).
You got /3 concepts.
Describe the importance of the base case in a recursive factorial function.
What happens if the function never stops calling itself?
You got /3 concepts.
