Ap Csa 2021 Frq 4 Arrayresizer

FRQ Archive2021 FRQs › FRQ 4: ArrayResizer
2021 AP CSA • 2D Array

AP CSA 2021 FRQ 4: ArrayResizer

Complete solution, scoring rubric, and walkthrough — verified from the official College Board PDF

9 Points Medium Unit 4
Question Type 2D Array
Skills Tested 2D array row traversal, helper method chaining, two-index copy pattern
Difficulty Medium
Recommended Time 22 minutes

What This Problem Asks

2021 AP CSA FRQ 4 ArrayResizer asks students to write two static methods. isNonZeroRow returns true if every element in a specified row is non-zero. resize creates a new 2D array containing only the rows that pass isNonZeroRow, using numNonZeroRows to size the new array and a separate index for insertion.

What This FRQ Tests

This FRQ tests Unit 4: 2D Arrays and Unit 2 (boolean short-circuit, nested loops, helper method usage).

Official Question & PDF

Download Full FRQ PDF →

PDF cannot display on this device. Open PDF directly →

Timer 22:00

Provided Code

public class ArrayResizer
{
    /** Returns true if all elements in row r of array2D are non-zero. */
    public static boolean isNonZeroRow(int[][] array2D, int r)
    { /* to be implemented in part (a) */ }
    /** Returns the number of rows with all non-zero values. */
    public static int numNonZeroRows(int[][] array2D)
    { /* implementation not shown */ }
    /** Returns a new 2D array containing only rows with no zeros.
     *  Precondition: at least one row with no zeros exists. */
    public static int[][] resize(int[][] array2D)
    { /* to be implemented in part (b) */ }
}

Part A — 4 Points

Write isNonZeroRow: return true if and only if every element in row r of array2D is non-zero.

Write Your Solution

Drag corner to expand ▽

 

Scoring Rubric (Part A — 4 points)

+1 Traverses row r of array2D
+1 Compares each element to zero (using != 0 or == 0)
+1 Returns false if any element is zero
+1 Returns true if and only if all elements are non-zero (algorithm)

Solution

public static boolean isNonZeroRow(int[][] array2D, int r)
{
    for (int c = 0; c < array2D[r].length; c++)
    {
        if (array2D[r][c] == 0)
        {
            return false;
        }
    }
    return true;
}

Part B — 5 Points

Write resize: return a new 2D array containing only the rows from array2D that have no zero values, in the same order. Must use both numNonZeroRows and isNonZeroRow.

Write Your Solution

Drag corner to expand ▽

 

Scoring Rubric (Part B — 5 points)

+1 Creates a new 2D array of the correct size using numNonZeroRows
+1 Calls isNonZeroRow to identify rows to include
+1 Copies qualifying rows from array2D to the new array
+1 Maintains original row order (algorithm)
+1 Returns the new array

Solution

public static int[][] resize(int[][] array2D)
{
    int newRows = numNonZeroRows(array2D);
    int[][] result = new int[newRows][array2D[0].length];
    int nextRow = 0;
    for (int r = 0; r < array2D.length; r++)
    {
        if (isNonZeroRow(array2D, r))
        {
            result[nextRow] = array2D[r];
            nextRow++;
        }
    }
    return result;
}
Two row indices: r iterates over all rows of the original array. nextRow tracks where to insert the next qualifying row in the result. These must be separate variables.

Common Mistakes to Avoid

Creating the result array with the wrong number of rows

Use numNonZeroRows(array2D) to get the correct number of rows, not array2D.length.

Wrong

int[][] result = new int[array2D.length][array2D[0].length];

Correct

int[][] result = new int[numNonZeroRows(array2D)][array2D[0].length];

Exam Tips

For resize, you need two row counters: one for the source array (r) and one for the destination array (nextRow). They increment at different rates.
Part B says "Assume isNonZeroRow works as intended." Use it — the rubric specifically requires calling both numNonZeroRows and isNonZeroRow.

Scoring Summary

Part Method Points
Part A Write 4
Part B Write 5
Total 9

Want the Complete 2021 FRQ Solutions?

Browse all past AP CSA FRQs with full solutions and scoring breakdowns.

FRQ Archive →

Related FRQs

2D Array 2022 FRQ 4: Data — Random fill with constraints and column increasing check 2D Array 2023 FRQ 4: BoxOfCandy — 2D array column operations and specified traversal

Study the Concepts

Unit 4 Study Guide →

Struggling with FRQs? Get 1-on-1 Help

Work directly with Tanner — AP CS teacher with 11+ years experience and 1,845+ verified tutoring hours. 54.5% of students score 5s (vs. 25.5% national average).

5.0Rating (451+ reviews)
1,845+Verified Hours
54.5%Score 5s

Book a Session ($150/hr) →

5-session packages at $125/hr. Venmo, Zelle, PayPal, or credit card.

Frequently Asked Questions

What does 2021 AP CSA FRQ 4 ArrayResizer test?

FRQ 4 tests 2D array traversal and helper method usage. isNonZeroRow checks one row for any zero values. resize creates a new 2D array containing only rows that pass isNonZeroRow, using numNonZeroRows to determine the new array size.

How many points is FRQ 4 worth?

9 points: 4 for Part A (isNonZeroRow) and 5 for Part B (resize).

Why do resize use two row index variables?

r iterates all rows of the original array. nextRow tracks where to insert the next qualifying row in the result array. They increment at different rates.

What happens if array2D[0] is used for column count?

array2D[0].length gives the number of columns, which is guaranteed to be the same for all rows in a rectangular 2D array. This is safe and is the standard approach.

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]