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 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.
Click to reveal answer
beginner
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.
Click to reveal answer
intermediate
How does the recursive factorial function calculate factorial for n > 1?
It multiplies n by the factorial of (n - 1), calling itself with a smaller number until it reaches the base case.
Click to reveal answer
beginner
Show the TypeScript function signature for a recursive factorial function.
function factorial(n: number): numberClick to reveal answer
What is the factorial of 0?
✗ Incorrect
By definition, 0! is 1 to serve as the base case in factorial calculations.
In recursion, what prevents infinite calls?
✗ Incorrect
The base case stops recursion by providing a simple answer without further calls.
What does factorial(4) compute in recursion?
✗ Incorrect
factorial(4) calls factorial(3) and multiplies the result by 4.
Which of these is a correct base case for factorial recursion?
✗ Incorrect
The base case returns 1 when n is 0 to stop recursion.
What will happen if the base case is missing in a recursive factorial function?
✗ Incorrect
Without a base case, recursion never stops, causing a stack overflow error.
Explain how a recursive function calculates the factorial of a number.
Think about how the problem is broken down into smaller parts.
You got /4 concepts.
Write the base case and recursive step for a factorial function in simple words.
Focus on what stops the recursion and what repeats.
You got /2 concepts.