Recall & Review
beginner Click to reveal answer
What is the base case in recursion?
The base case is the condition that stops the recursion. It prevents infinite calls by providing a simple answer without further recursion.
beginner Click to reveal answer
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.
beginner Click to reveal answer
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.
intermediate Click to reveal answer
Consider this C# recursive function snippet:
What are the base case and recursive case here?
int Factorial(int n) {
if (n == 0) return 1; // base case
return n * Factorial(n - 1); // recursive case
}What are the base case and recursive case here?
Base case: if (n == 0) return 1; stops recursion.
Recursive case: return n * Factorial(n - 1); calls itself with smaller input.
Recursive case: return n * Factorial(n - 1); calls itself with smaller input.
beginner Click to reveal answer
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.
What is the purpose of the base case in recursion?
✗ Incorrect
The base case stops the recursion by returning a result without further calls.
In the recursive case, what does the function usually do?
✗ Incorrect
The recursive case calls the function itself with a smaller input to approach the base case.
What will happen if a recursive function lacks a base case?
✗ Incorrect
Without a base case, recursion never stops, causing a stack overflow error.
In this code snippet, what is the base case?
int Sum(int n) {
if (n == 0) return 0;
return n + Sum(n - 1);
}✗ Incorrect
The base case is the condition that stops recursion: if n is 0, return 0.
Which of these is NOT true about recursion?
✗ Incorrect
Recursion does not always use loops; it uses function calls to itself.
Explain in your own words what the base case and recursive case are in recursion.
Think about how recursion stops and how it continues.
You got /3 concepts.
Describe what would happen if a recursive function does not have a base case.
Imagine a function calling itself forever without stopping.
You got /3 concepts.
