Recall & Review
beginner
What is the base case in recursion?
The base case is the condition that stops the recursion. It prevents infinite calls by returning a simple, direct answer.
Click to reveal answer
beginner
What is the recursive case in recursion?
The recursive case is where the function calls itself with a smaller or simpler input, moving towards the base case.
Click to reveal answer
intermediate
Why do we need both base case and recursive case in a recursive function?
The base case stops the recursion to avoid infinite loops, and the recursive case breaks the problem into smaller parts to solve it step by step.
Click to reveal answer
beginner
In the factorial function, what is the base case and what is the recursive case?<br><pre>function factorial(n: number): number { if (n === 0) return 1; return n * factorial(n - 1); }</pre>Base case: when n === 0, return 1.<br>Recursive case: return n * factorial(n - 1), calling itself with smaller n.
Click to reveal answer
beginner
What happens if a recursive function has no base case?
The function will keep calling itself forever, causing a stack overflow error because it never stops.
Click to reveal answer
What does the base case in recursion do?
✗ Incorrect
The base case stops the recursion by providing a direct answer.
Which part of recursion calls the function itself?
✗ Incorrect
The recursive case calls the function itself with a smaller input.
What will happen if a recursive function lacks a base case?
✗ Incorrect
Without a base case, recursion never stops and causes a stack overflow error.
In the factorial function, what is the base case?
✗ Incorrect
The base case for factorial is when n equals 0, returning 1.
Why is the recursive case important?
✗ Incorrect
The recursive case breaks the problem into smaller parts to solve it step by step.
Explain the roles of the base case and recursive case in a recursive function.
Think about how recursion stops and how it continues.
You got /3 concepts.
Describe what happens when a recursive function is missing a base case.
What happens if the function never stops calling itself?
You got /3 concepts.