2D Array Mistakes That Tank Your AP CSA Score

Unit 4 — FRQ 4 Topic

2D Array Mistakes That Tank Your AP CSA Score

FRQ 4 is always 2D arrays. These are the mistakes that cost students the most points on nested loop problems.

AP CSA Exam: May 15, 2026. FRQ 4 is always 2D arrays. Get these patterns locked in.

Mistake #1

Swapping Row and Column Bounds

This is the #1 2D array error. grid.length is the number of rows. grid[0].length is the number of columns. Swap them and your loop crashes on non-square grids.

WRONG
int[][] grid = new int[3][5]; // 3 rows, 5 cols
for (int r = 0; r < grid[0].length; r++)  // 5, but only 3 rows
{
    for (int c = 0; c < grid.length; c++)  // 3, but 5 cols
    {
        System.out.print(grid[r][c] + " ");
        // crashes when r = 3
    }
}
CORRECT
for (int r = 0; r < grid.length; r++)       // rows
{
    for (int c = 0; c < grid[0].length; c++) // cols
    {
        System.out.print(grid[r][c] + " ");
    }
}
Write this on scratch paper: Outer = rows = grid.length. Inner = cols = grid[0].length. Do this at the start of every 2D array problem.

Mistake #2

Accessing [col][row] Instead of [row][col]

In Java 2D arrays, the first index is always the row and the second is always the column. Writing grid[c][r] reads the wrong cell.

// grid has 3 rows, 5 columns
// To access row 1, column 3:
int val = grid[1][3];  // CORRECT
int val = grid[3][1];  // WRONG — accesses row 3 (may be out of bounds)
Exam tip: When the MCQ says “the element in row r, column c,” the answer uses grid[r][c] — always row first.

Mistake #3

Assuming the Grid Is Square

Students assume grid.length == grid[0].length and use a single variable for both bounds. This works for square grids but crashes for rectangular ones.

WRONG
int size = grid.length;
for (int r = 0; r < size; r++)
{
    for (int c = 0; c < size; c++)  // wrong if grid is 3x5
    {
        // ...
    }
}
Rule: Always use grid.length and grid[0].length separately. Never assume they are equal unless the problem explicitly states a square grid.

Crush FRQ 4 on Exam Day

2D arrays are worth 9 points on FRQ 4. Get a structured study plan that covers every pattern.

Get the Cram Kit — $29.99 1-on-1 Tutoring

Mistake #4

Off-by-One in Neighbor Access

Accessing grid[r-1][c] or grid[r][c+1] without checking bounds first. The edges and corners have fewer neighbors.

CRASHES ON EDGES
for (int r = 0; r < grid.length; r++)
{
    for (int c = 0; c < grid[0].length; c++)
    {
        int above = grid[r - 1][c];  // crashes when r = 0
    }
}
CORRECT: Check bounds first
for (int r = 0; r < grid.length; r++)
{
    for (int c = 0; c < grid[0].length; c++)
    {
        if (r > 0)
        {
            int above = grid[r - 1][c];  // safe
        }
    }
}

Mistake #5

Using Enhanced For Loop and Losing Indices

The enhanced for loop on a 2D array gives you each row as a 1D array. You lose access to the row index, which many FRQ problems require.

// Enhanced for on 2D array:
for (int[] row : grid)
{
    for (int val : row)
    {
        // You have the value but NOT the row or column index
        // Cannot do grid[r][c] = something
    }
}
FRQ rule: If the problem asks you to set or modify elements, or if you need the row/column index, use standard nested for loops. Enhanced for is only safe for read-only operations where you do not need position.

Mistake #6

Column-Major Traversal When Row-Major Is Expected

Row-major (outer loop = rows) visits all columns in row 0, then all columns in row 1, etc. Column-major (outer loop = columns) visits all rows in column 0 first. The exam specifies which order to use — using the wrong one produces different output.

COLUMN-MAJOR (outer = cols)
for (int c = 0; c < grid[0].length; c++)
{
    for (int r = 0; r < grid.length; r++)
    {
        System.out.print(grid[r][c] + " ");
    }
}
// Visits: (0,0) (1,0) (2,0) (0,1) (1,1) ...
ROW-MAJOR (outer = rows) — default
for (int r = 0; r < grid.length; r++)
{
    for (int c = 0; c < grid[0].length; c++)
    {
        System.out.print(grid[r][c] + " ");
    }
}
// Visits: (0,0) (0,1) (0,2) (1,0) (1,1) ...
Exam pattern: The MCQ shows a nested loop and asks what order elements are visited, or what the output is. You must identify whether the outer loop iterates rows or columns to trace correctly.

Master 2D Arrays Before May 15

54.5% of my AP CSA students score 5s. Get expert help on the hardest topics.

4-Week Cram Kit — $29.99 Book Tutoring

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]