AP CSA 4.16 Exercise 2: Recursion Applied Practice

Unit 4: Data Collections · Lesson 4.16 · Exercise 2

Recursion: Applied Practice

Six scenarios on base cases, the call stack, and why a recursive method that looks right still runs forever.

How this one is different

The exercise-1 editor asks you to write a recursive method. These six ask what makes the recursion terminate, and what the machine is actually doing while it waits.

Applied Practice

6 questions · scenario driven · every answer is recorded for your teacher

Question 1 of 6Analyze
A recursive method has a correct base case but the recursive call passes the same argument it received.
What happens?
Correct. Correct. A base case is necessary but not sufficient; progress toward it is the other half.
Incorrect. It does not terminate at all.
Incorrect. The compiler cannot tell whether an argument makes progress.
Incorrect. The base case is never reached, so it is never returned.
Question 2 of 6Apply
A factorial method is written with the recursive case return n * fact(n - 1); and no base case at all.
What is the result for fact(5)?
Incorrect. Multiplying by fact(-1) never resolves, so no value is ever produced.
Incorrect. Missing base cases are a logic error, not a compile error.
Incorrect. Reaching 120 requires something to stop the descent at 1 or 0.
Correct. Correct. Nothing about reaching 0 stops a recursion; only an explicit base case does.
Question 3 of 6Analyze
A recursive method is called with a large input and the program stops with StackOverflowError.
What does that indicate?
Incorrect. The data size matters only through how deep it drives the recursion.
Incorrect. It never returned any value; it ran out of room first.
Correct. Correct, and it is why deep recursion is sometimes rewritten as a loop.
Incorrect. The call stack lives in memory and is unrelated to disk.
Question 4 of 6Apply
A method computes the sum of an array recursively.
Which pair of cases is correct?
Incorrect. The recursive case makes no progress, so it never reaches the base.
Correct. Correct: the range shrinks by exactly one element per call and the empty range terminates it.
Incorrect. Returning a length is not a sum, and the recursive case is unspecified.
Incorrect. The base is fine but the recursive case does not shrink the range.
Question 5 of 6Evaluate
A student claims any recursive method can be rewritten as a loop, and vice versa.
Is that accurate?
Correct. Correct. Clarity and stack depth are the real trade-offs, not capability.
Incorrect. Neither form is more powerful than the other.
Incorrect. Recursion is usually slower, carrying call overhead a loop avoids.
Incorrect. Anything recursive can be done iteratively, sometimes with an explicit stack.
Question 6 of 6Analyze
A recursive method prints its argument BEFORE the recursive call; a second prints AFTER it.
How do their outputs relate for the same input?
Incorrect. It prints once per call, the same number of times as the first.
Incorrect. Every level prints; only the timing changes.
Incorrect. The ordering differs, which is the entire point of the comparison.
Correct. Correct, and this is the clearest demonstration that pending calls resume in reverse order.

Where to go next

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]