Recall & Review
beginner
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.
Click to reveal answer
beginner
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.
Click to reveal answer
beginner
How does the factorial function call itself recursively?
The factorial function calls itself with the number minus one (n-1) and multiplies the result by n, building the factorial step by step.
Click to reveal answer
intermediate
What happens if a recursive function does not have a base case?
Without a base case, the function will keep calling itself forever, causing the program to crash or run out of memory.
Click to reveal answer
beginner
Write the recursive formula for factorial of n.
factorial(n) = n * factorial(n-1), with factorial(0) = 1
Click to reveal answer
What is the factorial of 0?
✗ Incorrect
By definition, factorial of 0 is 1.
In a recursive factorial function, what stops the recursion?
✗ Incorrect
The base case stops the recursion by providing a simple answer.
What does factorial(5) compute to?
✗ Incorrect
5! = 5 * 4 * 3 * 2 * 1 = 120
Which of these is a correct recursive call in factorial function?
✗ Incorrect
The function calls itself with n-1 to reduce the problem size.
What will happen if the base case is missing in recursion?
✗ Incorrect
Without a base case, recursion never stops, causing a crash.
Explain how a recursive factorial function works step-by-step for input 3.
Think about how the function calls itself and returns values.
You got /5 concepts.
Describe why a base case is important in recursion and what it should be for factorial.
Base case is the simplest problem answer.
You got /4 concepts.