Ap Csa 2022 Frq 4 Data
AP CSA 2022 FRQ 4: Data
Complete solution, scoring rubric, and walkthrough — verified from the official College Board PDF
| Question Type | 2D Array |
| Skills Tested | 2D array nested loops, Math.random() with constraints, rejection sampling, column traversal |
| Difficulty | Medium-Hard |
| Recommended Time | 22 minutes |
What This Problem Asks
2022 AP CSA FRQ 4 Data asks students to write two methods for a 2D array class. repopulate fills every cell with a random integer between 1 and MAX that is divisible by 10 but not by 100 (using rejection sampling or direct formula). countIncreasingCols counts how many columns have non-decreasing values from top to bottom.
What This FRQ Tests
This FRQ tests Unit 4: 2D Arrays and Unit 2: Selection & Iteration (Math.random(), modulo operator, nested loops, boolean flags).
Official Question & PDF
PDF cannot display on this device. Open PDF directly →
Provided Code
public class Data
{
public static final int MAX = /* value not shown */;
private int[][] grid;
/** Fills all elements of grid with randomly generated values.
* Each value: between 1 and MAX inclusive, divisible by 10, NOT divisible by 100.
* Precondition: grid is not null, grid has at least one element. */
public void repopulate() { /* to be implemented in part (a) */ }
/** Returns the number of columns in grid that are in increasing order.
* A column is in increasing order if each row's element >= previous row's element.
* Precondition: grid is not null, grid has at least one element. */
public int countIncreasingCols() { /* to be implemented in part (b) */ }
}
Part A — 4 Points
Write repopulate, which fills every element of grid with a randomly generated value between 1 and MAX inclusive, divisible by 10, and not divisible by 100. All valid values must have equal probability of being chosen.
Write Your Solution
Scoring Rubric (Part A — 4 points)
| +1 | Traverses all elements of grid with no bounds errors |
| +1 | Generates a random value using Math.random() scaled to 1–MAX, cast to int |
| +1 | Correctly identifies values that are divisible by 10 AND NOT divisible by 100 |
| +1 | Assigns only valid values to grid elements (algorithm — loop until valid or rejection sampling) |
Solution (Rejection Sampling)
public void repopulate()
{
for (int r = 0; r < grid.length; r++)
{
for (int c = 0; c < grid[0].length; c++)
{
int val;
do
{
val = (int)(Math.random() * MAX) + 1;
} while (val % 10 != 0 || val % 100 == 0);
grid[r][c] = val;
}
}
}
Part B — 5 Points
Write countIncreasingCols, which returns the number of columns in grid where each element in each row after the first is >= the element in the previous row.
Write Your Solution
Scoring Rubric (Part B — 5 points)
| +1 | Traverses each column with no bounds errors |
| +1 | Compares adjacent elements within a column using < (if next element is LESS, not increasing) |
| +1 | Uses a flag or early return to mark a column as not-increasing |
| +1 | Correctly counts only columns that are in increasing order (algorithm) |
| +1 | Returns the count |
Solution
public int countIncreasingCols()
{
int count = 0;
for (int c = 0; c < grid[0].length; c++)
{
boolean increasing = true;
for (int r = 1; r < grid.length; r++)
{
if (grid[r][c] < grid[r-1][c])
{
increasing = false;
}
}
if (increasing)
{
count++;
}
}
return count;
}
grid[r][c] < grid[r-1][c]. “Increasing order” here allows equal consecutive values.Common Mistakes to Avoid
A column is in increasing order if each next element is >= the previous. If grid[r][c] < grid[r-1][c], the column is not increasing. Checking > instead gets the logic backwards.
When comparing grid[r][c] to grid[r-1][c], the inner loop must start at row 1, not row 0.
Wrong
for (int r = 0; r < grid.length; r++) {
if (grid[r][c] < grid[r-1][c]) // ArrayIndexOutOfBounds when r=0!
Correct
for (int r = 1; r < grid.length; r++) { // start at 1
if (grid[r][c] < grid[r-1][c])
Exam Tips
Scoring Summary
| Part | Method | Points |
|---|---|---|
| Part A | Write |
4 |
| Part B | Write |
5 |
| Total | 9 |
Want the Complete 2022 FRQ Solutions?
Browse all past AP CSA FRQs with full solutions and scoring breakdowns.
Related FRQs
2D Array 2021 FRQ 4: ArrayResizer — Filter 2D array rows with no zero values 2D Array 2023 FRQ 4: BoxOfCandy — 2D array column operations and specified traversalStudy the Concepts
Unit 4 Study Guide → Unit 2 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-session packages at $125/hr. Venmo, Zelle, PayPal, or credit card.
Frequently Asked Questions
What does 2022 AP CSA FRQ 4 Data test?
FRQ 4 tests 2D array traversal and Math.random(). repopulate fills a 2D array with random values meeting specific divisibility criteria. countIncreasingCols checks each column for non-decreasing order.
How many points is FRQ 4 Data worth?
9 points: 4 for Part A (repopulate) and 5 for Part B (countIncreasingCols).
Why is rejection sampling valid for repopulate?
Generating a random value in range 1-MAX and rejecting it if invalid (not divisible by 10, or divisible by 100) is a valid approach that the College Board accepts. It’s simpler to write under exam conditions than direct formula generation.
What does 'increasing order' mean in countIncreasingCols?
Each element must be greater than or equal to the element in the row above it. Equal consecutive values are allowed. A column with only one row is always in increasing order.
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.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]