2013 AP CSA FRQ 3: Skyview - Solution

2013 AP CSA FRQ 3: Skyview

Topic: 2D Arrays & Data Reconstruction

Skills: 1D to 2D conversion, row-column mapping, constructor logic

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

Points: 9 | Time: ~22 minutes

Part (a)

Write the Skyview constructor that fills a 2D array from 1D data.

Try First! Attempt before viewing solution.

Solution

public Skyview(int numRows, int numCols, double[] scanned)
{
    view = new double[numRows][numCols];
    int index = 0;
    
    for (int r = 0; r < numRows; r++)
    {
        if (r % 2 == 0)
        {
            for (int c = 0; c < numCols; c++)
            {
                view[r][c] = scanned[index];
                index++;
            }
        }
        else
        {
            for (int c = numCols - 1; c >= 0; c--)
            {
                view[r][c] = scanned[index];
                index++;
            }
        }
    }
}

Part (b)

Write the getAverage method for a rectangular region.

Solution

public double getAverage(int startRow, int endRow, int startCol, int endCol)
{
    double sum = 0;
    int count = 0;
    
    for (int r = startRow; r <= endRow; r++)
    {
        for (int c = startCol; c <= endCol; c++)
        {
            sum += view[r][c];
            count++;
        }
    }
    return sum / count;
}

Key Concepts

✓ Boustrophedon (alternating direction) fill pattern
✓ Even rows: left to right, odd rows: right to left
✓ Track single index through 1D array
✓ Inclusive bounds in getAverage

Common Mistakes

Wrong direction logic for odd rows
Off-by-one in loop bounds
Integer division for average
Not creating 2D array in constructor
Practice Similar: 2019 FRQ 4 | 2022 FRQ 4 | 2023 FRQ 4

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

tanner@apcsexamprep.com

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at tanner@apcsexamprep.com