01
Overview

Three classics in one traversal.

Sum every element, count those matching a condition, and locate the index of the minimum — all in a single pass.

The three most common array-traversal computations — total sum, conditional count, and argmin — can run side by side in one loop. Each uses its own accumulator; all share the same iteration.

Combining them is more efficient than three separate loops and demonstrates clean accumulator discipline.

On the AP exam, these three patterns appear individually and in combination — and recognizing all three quickly is a sign of array fluency.

02
Core Concept

Three accumulators, one loop.

Sum grows, count grows conditionally, argmin updates on improvement.

Combined template

int sum = 0;
int count = 0;
int minIndex = 0;
int minValue = arr[0];

for (int i = 0; i < arr.length; i++) {
    sum += arr[i];
    if (arr[i] > threshold) count++;
    if (arr[i] < minValue) {
        minValue = arr[i];
        minIndex = i;
    }
}

Initialization checklist

  • Sum: 0.
  • Count: 0.
  • minValue: arr[0] (not 0 or Integer.MAX_VALUE for clarity).
  • minIndex: 0.

Each pattern alone

// Sum only
int sum = 0;
for (int n : arr) sum += n;

// Conditional count only
int count = 0;
for (int n : arr) if (n > threshold) count++;

// Argmin only
int minIndex = 0;
for (int i = 1; i < arr.length; i++) {
    if (arr[i] < arr[minIndex]) minIndex = i;
}
03
Key Vocabulary

Combined-accumulator vocabulary.

Three patterns; one loop.

Vocabulary
  • Sum — total of all elements.
  • Conditional count — number of elements matching a predicate.
  • Argmin — index of the minimum value.
  • Accumulator — variable updated each iteration.
  • Combined pass — multiple computations in one loop.
  • Initialization — starting value before the loop.
04
AP Exam Focus

How combined patterns are tested.

Initialization and return type confusion dominate.

Exam Focus
  • Init minValue to arr[0]. Not 0 — fails on all-negative arrays.
  • Return index for argmin. Not the value.
  • Condition direction. Read prompt carefully ("above" vs "at least").
  • One pass is fine. Separate loops are not penalized but unnecessary.
05
Worked Example

All three in one pass.

Trace each accumulator.

Worked Example AP-style reasoning

Input: [7, 3, 9, 1, 5], threshold = 4.

Trace.

  • i=0: sum=7; count=1 (7>4); minIndex=0, minValue=7.
  • i=1: sum=10; count=1; 3<7 → minIndex=1, minValue=3.
  • i=2: sum=19; count=2; 9 not min.
  • i=3: sum=20; count=2; 1<3 → minIndex=3, minValue=1.
  • i=4: sum=25; count=3 (5>4); 5 not min.

Results: sum=25, count=3, argmin=3.

06
Common Mistakes

Combined-pattern pitfalls.

Most come from initializations.

Watch Out
  • minValue = 0. Breaks for all-negative arrays.
  • Returning minValue when argmin is asked for. Read the prompt.
  • Updating only minIndex without minValue. They must move together.
  • Confusing > with >=. Strict vs non-strict changes tie behavior.
07
Reference Table

Three-pattern initializations.

Side by side.

Combined Accumulator Reference

AP Quick Reference
PatternInitializeUpdate
Sum0sum += arr[i]
Conditional count0if (cond) count++
Argmin index0Update when smaller.
Argmin valuearr[0]Update alongside index.
08
Practice Tip

How to master combined accumulators.

Three accumulators in one loop — drill until automatic.

Practice Strategy
  • MCQ Practice — verify each accumulator updates with the right operator and inside the right branch.
  • Java Lab — implement combinedStats returning all three values. Test with negatives and ties.
  • FRQ Practice — when an FRQ wants several aggregates, combine into one pass for clean code.
09
Section · 09

Practice — attempt these now.

AP-style assessments aligned to this lesson. Time them.

FRQ Practice 30 min 18 marks Pending

AP CSA Unit 07 Topic 15 Sum, Conditional Count, and Argmin FRQ Practice

AP-style topic practice assessment

Start