AP® Computer Science A glossary

Row-major order

Also called: row by row

Course: AP® Computer Science A Shows up in: Unit 4: Data Collections

A 2D array traversal that moves across each row, left to right, before going down to the next row.

Appears in the course and exam description (CED): 4.12.A.1

In row-major order the outer loop chooses a row and the inner loop visits every column of that row. A nested enhanced for loop always traverses a 2D array in row-major order.

Example

for (int r = 0; r < grid.length; r++)
{
    for (int c = 0; c < grid[0].length; c++)
    {
        System.out.print(grid[r][c] + " ");
    }
}
Learn it properly, with a checkpoint 4.12 2D Array Traversals

Related terms

Was this page helpful?

No names are ever shown, and every public comment is checked by us first. Please do not include personal details. To get a reply, email [email protected].

↑ Top

Enlarged view of the selected figure