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 a base case in recursion?
A base case is the simplest situation in a recursive function that stops the recursion by not calling itself again.
Click to reveal answer
intermediate
How does the call stack help in recursion?
The call stack keeps track of all the active function calls. Each recursive call adds a new layer, and when a base case is reached, the stack unwinds as functions return their results.
Click to reveal answer
intermediate
What happens if a recursive function has no base case?
Without a base case, the recursive function keeps calling itself forever, causing a stack overflow error because the call stack grows too large.
Click to reveal answer
beginner
Explain the flow of a simple factorial function using recursion.
The factorial function calls itself with smaller numbers until it reaches 1 (base case). Then it returns 1, and each previous call multiplies its number by the returned value, building the final result.
Click to reveal answer
What is the purpose of the base case in a recursive function?
✗ Incorrect
The base case stops the recursion by providing a simple answer without further calls.
What does the call stack do during recursion?
✗ Incorrect
The call stack keeps track of each recursive call until the base case is reached and functions return.
What error occurs if a recursive function never reaches a base case?
✗ Incorrect
Without a base case, the call stack grows until it runs out of space, causing a stack overflow.
In the factorial example, what does factorial(3) call next?
✗ Incorrect
factorial(3) calls factorial(2) to solve a smaller problem.
Which of these is NOT true about recursion?
✗ Incorrect
Recursion does not require loops; it uses function calls to repeat.
Describe how the call stack changes during a recursive function call.
Think about how each call waits for the next before finishing.
You got /4 concepts.
Explain why a base case is essential in recursion and what happens if it is missing.
Consider what stops the function from calling itself forever.
You got /4 concepts.