AP CSA Recursion Trace Problems with Solutions (2026)

AP CSA Recursion Trace Problems with Solutions

Practice tracing recursive methods exactly the way the AP CSA exam tests them. Each problem gives you a method and a specific call — your job is to trace through and determine the return value or output. Full step-by-step solutions included.

⏰ The AP CSA Exam is May 15, 2026 — Get the 4-Week Cram Kit →
🎓 How to Use This Page

For each problem: (1) Read the method carefully. (2) Write your trace on paper before looking at the answer. (3) Click to reveal the solution. (4) Compare your trace to the solution step by step. If you got the answer right but your trace was wrong, you got lucky — fix your method.

✏ Problems

Score: 0 / 10
1.
public static int puzzle(int n)
{
    if (n < 2)
    {
        return 1;
    }
    return puzzle(n - 1) + puzzle(n - 2);
}
What does puzzle(5) return?
2.
public static int reduce(int x)
{
    if (x <= 0)
    {
        return 0;
    }
    return x % 10 + reduce(x / 10);
}
What does reduce(4273) return?
3.
public static void countdown(int n)
{
    if (n <= 0)
    {
        System.out.print("Go! ");
        return;
    }
    System.out.print(n + " ");
    countdown(n - 1);
}
What does countdown(3) output?
4.
public static String flip(String s)
{
    if (s.length() <= 1)
    {
        return s;
    }
    int mid = s.length() / 2;
    return flip(s.substring(mid)) + flip(s.substring(0, mid));
}
What does flip("WXYZ") return?
5.
public static int power(int base, int exp)
{
    if (exp == 0)
    {
        return 1;
    }
    return base * power(base, exp - 1);
}
What does power(3, 4) return?
6.
public static void bounce(int n)
{
    if (n <= 0)
    {
        return;
    }
    bounce(n - 2);
    System.out.print(n + " ");
    bounce(n - 3);
}
What does bounce(4) output?
7.
public static int compress(int n)
{
    if (n < 10)
    {
        return n;
    }
    if (n % 10 > compress(n / 10))
    {
        return n % 10;
    }
    return compress(n / 10);
}
What does compress(3841) return?
8.
public static int chain(int n)
{
    if (n <= 1)
    {
        return n;
    }
    if (n % 2 == 0)
    {
        return chain(n / 2);
    }
    return 1 + chain(3 * n + 1);
}
What does chain(3) return?
9.
public static String weave(String a, String b)
{
    if (a.length() == 0)
    {
        return b;
    }
    if (b.length() == 0)
    {
        return a;
    }
    return a.substring(0, 1) + b.substring(0, 1)
         + weave(a.substring(1), b.substring(1));
}
What does weave("ACE", "BD") return?
10. How many total recursive calls (NOT counting the initial call) does puzzle(5) make, using the method from Problem 1?

❓ Frequently Asked Questions

How many recursion questions are on the AP CSA exam?

Typically 2-4 of the 42 MCQ involve recursion tracing. Binary search (which uses recursion) may appear as additional questions. Recursion does not appear on the FRQ section of the 2026 exam.

What difficulty level are these problems?

These problems match AP exam difficulty. They include numeric recursion, String recursion, print-before-and-after patterns, and methods with multiple recursive calls. Start with problems 1-4 if you are new to tracing.

Should I memorize recursion patterns?

No. Always trace step by step for the specific input given. Trying to recognize patterns (like factorial or fibonacci) can lead to errors when the method has a slight twist you did not expect.

About the Author: Tanner Crow has 11+ years of AP Computer Science teaching experience, 1,845+ verified tutoring hours, and a 5.0 rating. His students score 5s at over double the national rate. Book a tutoring session →

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]