AP Computer Science A Practice Quiz: Recursion
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 10 questions to check your progress.
Question 1 of 10
All Questions (10)
A) A for-loop and a while-loop
B) At least one base case and at least one recursive call
C) A parameter and a return value
D) A local variable and a call to a different method
Correct Answer: B
The content explicitly states that 'Recursive methods contain at least one base case, which halts the recursion, and at least one recursive call.' These are the fundamental requirements for recursion.
A) An if-else statement
B) A switch statement
C) A loop
D) Variable assignment
Correct Answer: C
Iteration is achieved through loops (like for or while loops). The content directly links recursion to repetition and iteration, making it functionally equivalent to a loop.
A) 1 2 3 4
B) 4 3 2 1
C) 4
D) 1
Correct Answer: B
The method first prints the current value of `n` and then calls itself with `n-1`. The call `countDown(4)` prints '4 ', then calls `countDown(3)`. `countDown(3)` prints '3 ', then calls `countDown(2)`. This continues until `countDown(1)` prints '1 ' and calls `countDown(0)`, which hits the base case (`n > 0` is false) and stops the recursion.
A) They are shared and have the same value across all recursive calls.
B) They are used only in the base case to halt the recursion.
C) They capture the progress of the recursion, similar to a loop control variable.
D) They must always be integers.
Correct Answer: C
The content states, 'Parameter values capture the progress of a recursive process, much like loop control variable values capture the progress of a loop.' Each call has its own set of parameters, tracking its specific state.
A) 5
B) 6
C) 9
D) 15
Correct Answer: C
The execution trace is as follows: - `mystery(5)` returns `5 + mystery(3)` - `mystery(3)` returns `3 + mystery(1)` - `mystery(1)` returns `1 + mystery(-1)` - `mystery(-1)` returns `0` (base case) Substituting back: `1 + 0 = 1`. Then `3 + 1 = 4`. Then `5 + 4 = 9`.
A) The method will print `1` and then terminate successfully.
B) The method will not compile because it has no return statement.
C) The method will cause a runtime error because it lacks a base case to halt recursion.
D) The method will print numbers indefinitely without error.
Correct Answer: C
The method continuously calls itself with an increasing value (`val + 1`), but there is no condition to stop the calls. This is a missing base case. The program will run out of memory for the call stack and produce a runtime error (typically a StackOverflowError).
A) "AP"
B) "PA"
C) "A"
D) "P"
Correct Answer: B
The execution trace is: - `reverse("AP")` calls `reverse("P")` and waits. It will append 'A' to the result. - `reverse("P")` calls `reverse("")` and waits. It will append 'P' to the result. - `reverse("")` hits the base case and returns "". - The `reverse("P")` call receives "" and returns "" + 'P', which is "P". - The `reverse("AP")` call receives "P" and returns "P" + 'A', which is "PA".
A) A change to a parameter in one recursive call will affect the parameter's value in all other calls.
B) The state of each step in the recursion is stored independently, preventing interference between calls.
C) Recursive methods cannot use local variables, only parameters.
D) Recursive methods are less memory-efficient than iterative solutions because they cannot have variables.
Correct Answer: B
Because each call has its own memory space for its parameters and local variables (its own 'frame' on the call stack), the state of one call is isolated from others. This allows the recursion to work its way back up, with each returning call having preserved its unique state.
A) It is impossible to implement the same algorithm using recursion.
B) The iterative approach is the only possible way to solve the problem.
C) An equivalent solution can be implemented using a recursive approach.
D) The recursive approach would be significantly more complex.
Correct Answer: C
The content explicitly states, 'Any recursive solution can be replicated through the use of an iterative approach and vice versa.' This means the two approaches are interchangeable for any given problem.
A) 3
B) 4
C) 5
D) 8
Correct Answer: C
This requires tracing multiple recursive branches: - `combo(4)` calls `combo(3)` + `combo(2)` - `combo(3)` calls `combo(2)` + `combo(1)`. `combo(1)` returns 1. - The first `combo(2)` calls `combo(1)` + `combo(0)`. Both return 1. So `combo(2)` returns 1 + 1 = 2. - So, `combo(3)` returns 2 + 1 = 3. - The second `combo(2)` (from the original call) also returns 2. - Finally, `combo(4)` returns the result of `combo(3)` + `combo(2)`, which is 3 + 2 = 5.