โ† All AP CSA Flashcard Decks

Recursion Flashcards

6 cards from real AP CSA practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 6 Recursion flashcards as text
  1. What is the base case in a recursive method?

    Answer: The condition that stops the recursion

    The base case is the condition that terminates recursion by returning a result without making further recursive calls.

  2. What error occurs when a recursive method has no base case or never reaches it?

    Answer: StackOverflowError

    Infinite recursion causes the call stack to fill up, resulting in a StackOverflowError at runtime.

  3. What does the following return? `public int f(int n) { if(n==0) return 0; return n + f(n-1); }` called with f(4)?

    Answer: 10

    f(4) = 4 + f(3) = 4+3+2+1+0 = 10, computing the sum of integers from 0 to n.

  4. In recursion, each method call gets its own set of local variables stored where?

    Answer: On the call stack

    Each recursive call creates a new stack frame on the call stack that holds its own local variables and parameters.

  5. Which of the following best describes mutual recursion?

    Answer: Two methods that each call the other

    Mutual recursion occurs when method A calls method B and method B calls method A, forming a cycle.

  6. What is the recursive case?

    Answer: The part of the method that makes a call to itself with a smaller/simpler input

    The recursive case is the branch that calls the method again with a modified argument, moving toward the base case.

Recursion Flashcards โ€” AP CSA Study Cards with Answers