AP CSA FRQ Guide
2021 FRQ 4: ArrayResizer
Write two static methods for resizing a 2D array. The first determines whether one row has no zero values. The second creates a new 2D array containing only rows that have no zeros, preserving row order.
Skills Tested
What this FRQ is really practicing
Treat these skills as the study checklist. If any tag feels shaky, review that topic before attempting the full written response.
Starter Approach
How to begin without copying a solution
- 1Part A: examine every column in row r and return false if any value is zero.
- 2Return true only when all values in the row are nonzero.
- 3Part B: use numNonZeroRows to create a result array with the correct number of rows.
- 4Copy only rows that pass isNonZeroRow, preserving their original order.
- 5Return the resized 2D array without changing array2D.
Write a first attempt before revealing any solution outline. Most AP CSA FRQ progress comes from tracing your own code and finding the missing case.
Common Mistakes
Mistakes to watch for while writing
Self Check
Review questions before you submit
Defines isNonZeroRow as a public static boolean method.
Part A is a static helper method with int[][] and row index parameters.
Traverses every column in row r.
Use array2D[0].length or array2D[r].length.
Returns false when a zero is found in row r.
Check array2D[r][col] == 0.
Returns true after the row is fully checked.
The true return belongs after the loop.
Defines resize as a public static method returning int[][].
Part B returns a new 2D int array.
Uses numNonZeroRows to size the result array.
The helper tells how many rows the new array needs.
Creates a new 2D array with original column count.
Use new int[numNonZeroRows(array2D)][array2D[0].length].
Calls isNonZeroRow to decide which rows to copy.
Part B should use the Part A helper.
Practice Links
