AP CSA Recursion 3 — Questions and Answers
Question 1: What is a recursive method that counts down from n printing each number called?
- Linear recursion (Correct answer)
- Binary recursion
- Tail recursion
- Mutual recursion
Correct answer: Linear recursion
A method making a single recursive call per invocation, working through a linear sequence, is called linear recursion.
Question 2: What must be true about the argument in each recursive call to guarantee termination?
- It must move closer to the base case (Correct answer)
- It must be larger than the original
- It must be the same value
- It must be a String
Correct answer: It must move closer to the base case
Each recursive call must use an argument that brings it closer to the base case, ensuring eventual termination.
Question 3: How many total method calls does factorial(4) make (including the initial call)?
- 5 (Correct answer)
- 4
- 3
- 6
Correct answer: 5
factorial(4) calls factorial(3), which calls factorial(2), factorial(1), and factorial(0) — 5 calls total including the first.
Question 4: Which of the following is NOT an advantage of recursion?
- Always more memory-efficient than iteration (Correct answer)
- Can simplify code for problems with recursive structure
- Natural fit for tree traversal
- Models mathematical induction directly
Correct answer: Always more memory-efficient than iteration
Recursion is not always more memory-efficient; each call uses stack space, so deep recursion can use more memory than iteration.
Question 5: What is 'unwinding the stack' in recursion?
- The process of returning from recursive calls back to the original caller (Correct answer)
- The process of making recursive calls deeper
- Clearing all local variables
- Throwing an exception from a recursive call
Correct answer: The process of returning from recursive calls back to the original caller
Stack unwinding is when recursive calls finish and return in reverse order, passing values back up to the original caller.
Question 6: In AP CSA, which searching algorithm is commonly implemented recursively?
- Binary search (Correct answer)
- Linear search
- Selection sort
- Bubble sort
Correct answer: Binary search
Binary search is naturally implemented recursively by halving the search space with each call until the target is found or the range is empty.
What is a recursive method that counts down from n printing each number called?