2011 AP CSA FRQ 1: Sound - Solution

2011 AP CSA FRQ 1: Sound

Topic: Arrays & Signal Processing

Skills: Array manipulation, trimming algorithms, index tracking

Unit: Unit 4 (Data Collections) (2025-2026 AP CSA)

Points: 9 | Time: ~22 minutes

Part (a)

Write the trimSilenceFromBeginning method that removes leading silence.

Try First! Attempt before viewing solution.

Solution

public void trimSilenceFromBeginning()
{
    int firstNonSilent = 0;
    while (firstNonSilent < samples.length && 
           Math.abs(samples[firstNonSilent]) <= limitAmplitude)
    {
        firstNonSilent++;
    }
    
    int[] newSamples = new int[samples.length - firstNonSilent];
    for (int i = 0; i < newSamples.length; i++)
    {
        newSamples[i] = samples[firstNonSilent + i];
    }
    samples = newSamples;
}

Part (b)

Write the limitAmplitude method that caps all values to a maximum.

Solution

public int limitAmplitude(int limit)
{
    int count = 0;
    for (int i = 0; i < samples.length; i++)
    {
        if (samples[i] > limit)
        {
            samples[i] = limit;
            count++;
        }
        else if (samples[i] < -limit)
        {
            samples[i] = -limit;
            count++;
        }
    }
    return count;
}

Key Concepts

✓ Find first index meeting condition
✓ Create new array with different size
✓ Copy elements with offset
✓ Handle both positive and negative limits

Common Mistakes

Not checking array bounds in while loop
Wrong array size calculation
Forgetting negative amplitude check
Not updating the instance variable

Official Resources

Author: Tanner Crow - AP CS Teacher, 11+ years

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]