AP® Computer Science A glossary

Column-major order

Also called: column by column

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

A 2D array traversal that moves down each column, top to bottom, before moving to the next column.

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

In column-major order the outer loop chooses a column (c < arr[0].length) and the inner loop visits every row (r < arr.length). The element is still written arr[r][c]; only the loop order changes.

Example

for (int c = 0; c < grid[0].length; c++)
{
    for (int r = 0; r < grid.length; r++)
    {
        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