---
title: "countIncreasingCols — AP CSA Definition & 2D Array Guide"
description: "countIncreasingCols counts how many columns of a 2D array are in increasing order. A classic AP CSA Topic 4.13 column-traversal algorithm worth mastering for FRQ 4."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/countincreasingcols"
type: "key-term"
subject: "AP Computer Science A"
unit: "Unit 4"
---

# countIncreasingCols — AP CSA Definition & 2D Array Guide

## Definition

countIncreasingCols is a method that traverses each column of a 2D array, checks whether every element in that column is greater than the one above it, and returns how many columns pass that test. It's a standard Topic 4.13 algorithm combining column traversal with an "all elements have a property" check.

## What It Is

countIncreasingCols is a practice [method](/ap-comp-sci-a/unit-3/abstraction-and-program-design/study-guide/o9VgVeIpKRYZ7N7rXfUz "fv-autolink") that combines two skills the AP CSA exam loves to mash together. First, you [traverse](/ap-comp-sci-a/key-terms/traverse "fv-autolink") the 2D array **by column**, which flips the usual loop order. Your outer loop runs over column indexes and your inner loop runs over row indexes, so you access elements as `arr[row][col]` while `col` stays fixed. Second, inside each column you run an "all elements have a property" check, asking whether `arr[row][col] < arr[row + 1][col]` for every adjacent pair. If a column never breaks that rule, it counts as increasing and you bump a counter.

The typical implementation uses a [boolean](/ap-comp-sci-a/unit-1/variables-and-primitive-data-types/study-guide/rezA6f3hJz84TKaY5Jjl "fv-autolink") flag (often called `isIncreasing`) reset to `true` at the start of each column. The inner loop only goes up to `arr.length - 1` (one short of the last row) because you're comparing each element to the one below it. Comparing past the last row is the classic off-by-one `ArrayIndexOutOfBoundsException` trap. Once all columns are checked, the method returns the count.

## Why It Matters

This lives in **[Unit 4](/ap-comp-sci-a/unit-4 "fv-autolink"): Data Collections, Topic 4.13 (Implementing 2D Array Algorithms)** and directly supports learning objective **4.13.A**, which asks you to develop code for standard and original [algorithms](/ap-comp-sci-a/key-terms/algorithm "fv-autolink") involving 2D arrays. The CED's essential knowledge (EK 4.13.A.1) explicitly lists "determine if all elements of a designated column have a particular property" and "determine the number of elements meeting specific criteria" as standard 2D array algorithms. countIncreasingCols is both at once, an all-check nested inside a count. It also forces column-major traversal, which is the single most common place AP students mix up `arr.length` (number of rows) and `arr[0].length` (number of columns).

## Connections

### [Traversal (Unit 4)](/ap-comp-sci-a/key-terms/traversal)

countIncreasingCols is just a column-major [traversal](/ap-comp-sci-a/key-terms/traversal "fv-autolink") with a job to do. If you can write a plain nested loop that visits every element column by column, this method is that loop plus a comparison and a counter.

### Boolean flag / all-check algorithms (Unit 4)

The inner logic is the classic "do ALL elements have a property" [pattern](/ap-comp-sci-a/unit-1/why-programming-why-java/study-guide/lVK6rmrBuug17i1Hna9z "fv-autolink") from 1D arrays, just aimed down a column. Start a flag at true, flip it to false the moment one pair breaks the rule, and never flip it back.

### [Duplicate elements (Unit 4)](/ap-comp-sci-a/key-terms/duplicate-elements)

Checking for duplicates uses the same adjacent-or-pairwise comparison muscle. In a strictly increasing column, duplicates are automatically impossible, since `arr[row][col] < arr[row+1][col]` fails when two neighbors are equal.

### [Shift algorithm (Unit 4)](/ap-comp-sci-a/key-terms/shift-algorithm)

Both algorithms live and die on careful [index](/ap-comp-sci-a/key-terms/index "fv-autolink") bounds. A shift moves elements using `i` and `i+1` style indexing, and countIncreasingCols compares `row` and `row+1`, so both require stopping the loop one slot early to avoid going out of bounds.

## On the AP Exam

2D array algorithms like this are core FRQ 4 territory. The 2022 FRQ Q4 had you write methods for a Data class built around a two-dimensional array of integers, exactly the kind of "original algorithm for a particular context" that 4.13.A describes. For a countIncreasingCols-style task, the points come from getting four things right: looping over columns with `arr[0].length`, looping rows with `arr.length`, stopping the comparison loop at `arr.length - 1`, and resetting your boolean flag for each new column. In MCQs, expect to trace a similar method on a small grid and pick the returned count, or spot the bug in a version that swaps row and column bounds.

## countIncreasingCols vs countIncreasingRows (row-version of the same algorithm)

Counting increasing rows compares left-to-right neighbors in the same row, so you fix `row` and compare `arr[row][col]` with `arr[row][col + 1]`, bounding the inner loop by `arr[0].length - 1`. countIncreasingCols compares top-to-bottom, fixing `col` and comparing `arr[row][col]` with `arr[row + 1][col]`, bounding by `arr.length - 1`. Same logic, swapped axes. If you mix up which index is fixed and which length bounds the loop, you'll either check the wrong direction or crash with an out-of-bounds exception.

## Key Takeaways

- countIncreasingCols returns the number of columns where every element is greater than the element directly above it.
- The traversal is column-major, meaning the outer loop runs over columns (bounded by arr[0].length) and the inner loop runs over rows (bounded by arr.length).
- The comparison loop must stop at arr.length - 1 because each element is compared to the one below it, and going further throws an ArrayIndexOutOfBoundsException.
- Use a boolean flag that resets to true at the start of each column and flips to false as soon as one adjacent pair fails the increasing test.
- This method is a combo of two CED standard algorithms from EK 4.13.A.1, the all-elements-have-a-property check and the count-elements-meeting-criteria pattern.

## FAQs

### What does countIncreasingCols do in AP Computer Science A?

It traverses each column of a 2D array, checks whether the values strictly increase from top to bottom, and returns the number of columns that do. It's a standard Topic 4.13 algorithm combining column traversal with an all-elements check.

### Is countIncreasingCols an actual term on the AP CSA exam?

No, it's a practice method name, not official vocabulary. But the underlying skill is straight from EK 4.13.A.1, and FRQ 4 regularly asks you to write this exact style of 2D array algorithm, like the 2022 FRQ Q4 built around a Data class with a 2D integer array.

### How is counting increasing columns different from counting increasing rows?

For columns you fix the column index and compare arr[row][col] to arr[row+1][col], stopping the loop at arr.length - 1. For rows you fix the row index and compare arr[row][col] to arr[row][col+1], stopping at arr[0].length - 1. Same pattern, opposite axis.

### Why does my countIncreasingCols code throw an ArrayIndexOutOfBoundsException?

Almost always because the inner loop runs to arr.length instead of arr.length - 1. Since you compare each element to the one below it, the last row has nothing below it, so the loop must stop one row early.

### Does arr.length give the number of columns in a 2D array?

No. In Java, arr.length is the number of rows, and arr[0].length is the number of columns. Mixing these up is the most common error in column-traversal methods like countIncreasingCols.

## Related Study Guides

- [4.13 Implementing 2D Array Algorithms](/ap-comp-sci-a/unit-4/implementing-2d-array-algorithms/study-guide/9ucC5cB6ffrLnA4b3FU3)

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/countincreasingcols#resource","name":"countIncreasingCols — AP CSA Definition & 2D Array Guide","url":"https://fiveable.me/ap-comp-sci-a/key-terms/countincreasingcols","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/countincreasingcols#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-11T05:27:19.732Z","isPartOf":{"@type":"Collection","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"},"publisher":{"@type":"Organization","name":"Fiveable","url":"https://fiveable.me"}},{"@type":"DefinedTerm","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/countincreasingcols#term","name":"countIncreasingCols","description":"countIncreasingCols is a method that traverses each column of a 2D array, checks whether every element in that column is greater than the one above it, and returns how many columns pass that test. It's a standard Topic 4.13 algorithm combining column traversal with an \"all elements have a property\" check.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/countincreasingcols","inDefinedTermSet":{"@type":"DefinedTermSet","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"}},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What does countIncreasingCols do in AP Computer Science A?","acceptedAnswer":{"@type":"Answer","text":"It traverses each column of a 2D array, checks whether the values strictly increase from top to bottom, and returns the number of columns that do. It's a standard Topic 4.13 algorithm combining column traversal with an all-elements check."}},{"@type":"Question","name":"Is countIncreasingCols an actual term on the AP CSA exam?","acceptedAnswer":{"@type":"Answer","text":"No, it's a practice method name, not official vocabulary. But the underlying skill is straight from EK 4.13.A.1, and FRQ 4 regularly asks you to write this exact style of 2D array algorithm, like the 2022 FRQ Q4 built around a Data class with a 2D integer array."}},{"@type":"Question","name":"How is counting increasing columns different from counting increasing rows?","acceptedAnswer":{"@type":"Answer","text":"For columns you fix the column index and compare arr[row][col] to arr[row+1][col], stopping the loop at arr.length - 1. For rows you fix the row index and compare arr[row][col] to arr[row][col+1], stopping at arr[0].length - 1. Same pattern, opposite axis."}},{"@type":"Question","name":"Why does my countIncreasingCols code throw an ArrayIndexOutOfBoundsException?","acceptedAnswer":{"@type":"Answer","text":"Almost always because the inner loop runs to arr.length instead of arr.length - 1. Since you compare each element to the one below it, the last row has nothing below it, so the loop must stop one row early."}},{"@type":"Question","name":"Does arr.length give the number of columns in a 2D array?","acceptedAnswer":{"@type":"Answer","text":"No. In Java, arr.length is the number of rows, and arr[0].length is the number of columns. Mixing these up is the most common error in column-traversal methods like countIncreasingCols."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"AP Computer Science A","item":"https://fiveable.me/ap-comp-sci-a"},{"@type":"ListItem","position":2,"name":"Key Terms","item":"https://fiveable.me/ap-comp-sci-a/key-terms"},{"@type":"ListItem","position":3,"name":"Unit 4","item":"https://fiveable.me/ap-comp-sci-a/unit-4"},{"@type":"ListItem","position":4,"name":"countIncreasingCols"}]}]}
```
