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 5 (5!)?
5! = 5 × 4 × 3 × 2 × 1 = 120
beginner Click to reveal answer
What is the base case in factorial recursion?
The base case is when n = 0, and factorial(0) = 1. This stops the recursion from continuing forever.
intermediate Click to reveal answer
How does the recursive factorial function calculate factorial(n)?
It calculates factorial(n) by multiplying n with factorial(n-1), breaking the problem into smaller parts until it reaches the base case.
intermediate Click to reveal answer
What happens if a recursive function does not have a base case?
Without a base case, the function calls itself forever, causing a stack overflow error and crashing the program.
What is the base case for factorial recursion?
✗ Incorrect
The base case stops recursion. For factorial, factorial(0) = 1 is the base case.
What does factorial(3) equal?
✗ Incorrect
factorial(3) = 3 × 2 × 1 = 6
In recursion, what is the function doing when it calls itself?
✗ Incorrect
Recursion solves problems by breaking them into smaller parts using self-calls.
What will happen if the base case is missing in a recursive factorial function?
✗ Incorrect
Without a base case, recursion never stops and causes a stack overflow error.
Which of these is the correct recursive formula for factorial(n)?
✗ Incorrect
The factorial of n is n times factorial of (n-1).
Explain how the factorial function uses recursion to calculate factorial of a number.
Think about how the function reduces the problem step by step.
You got /4 concepts.
Describe why a base case is important in recursive functions like factorial.
Without it, the function would never stop calling itself.
You got /4 concepts.
