01
Overview

Average and minimum — but only over qualifying elements.

When a stat applies only to elements that meet a condition, count only what counts.

Conditional average means averaging only elements that satisfy some test. Conditional minimum finds the smallest among those that qualify. Both patterns need careful handling of the case where no element qualifies — division by zero or a meaningless sentinel return.

The trick is a filtered accumulator: a sum and a counter that both grow only when the condition holds.

On the AP exam, this appears in FRQs like "average grade of students who passed" or "minimum price among items in stock".

02
Core Concept

Sum and count only the qualifying elements.

Guard the divide; guard the minimum.

Conditional average

public double averagePositive(int[] arr) {
    int sum = 0;
    int count = 0;
    for (int n : arr) {
        if (n > 0) {
            sum += n;
            count++;
        }
    }
    if (count == 0) return 0.0;   // or per spec
    return (double) sum / count;
}

Conditional minimum

public int minPositive(int[] arr) {
    int min = Integer.MAX_VALUE;
    boolean found = false;
    for (int n : arr) {
        if (n > 0 && n < min) {
            min = n;
            found = true;
        }
    }
    return found ? min : -1;
}

The found flag signals whether any element qualified — essential when the array might have no positives.

03
Key Vocabulary

Conditional-stat vocabulary.

Used in filtered-aggregate problems.

Vocabulary
  • Conditional accumulator — sum that grows only when the condition holds.
  • Conditional count — counter that grows only when the condition holds.
  • Empty-subset case — no qualifying elements.
  • Found flag — boolean tracking whether any qualifier was seen.
  • Sentinel return — value used when no qualifier exists.
04
AP Exam Focus

How conditional stats are tested.

Empty-subset handling and dividing by the right count dominate.

Exam Focus
  • Divide by the conditional count. Not arr.length.
  • Guard the divide. Return a sensible value if count is 0.
  • Cast for accurate division. Avoid integer truncation.
  • Found flag for minimum. Avoids returning Integer.MAX_VALUE as the answer.
05
Worked Example

Average and min of positives.

Trace both methods on the same input.

Worked Example AP-style reasoning

Input: [-3, 5, -1, 8, 2].

Average of positives: sum = 15, count = 3 → 15/3 = 5.0.

Min of positives: 2.

Edge case. If input were [-3, -1, -7], the average method returns 0.0 (or per spec) and the min method returns -1.

06
Common Mistakes

Conditional-stat pitfalls.

Most come from wrong divisor or missing guard.

Watch Out
  • Dividing by arr.length instead of conditional count. Skews the average.
  • No empty-subset guard. Division by zero crash.
  • Returning Integer.MAX_VALUE. Better to return -1 or per spec.
  • Combining the conditions awkwardly. Apply both: condition AND new min.
07
Reference Table

Conditional accumulators.

Sum, count, min — guarded by the same predicate.

Conditional Stats Reference

AP Quick Reference
StatInitializeEmpty case
Conditional sum0Returns 0.
Conditional count0Returns 0.
Conditional averagesum/countGuard divisor.
Conditional minInteger.MAX_VALUEFound flag.
08
Practice Tip

How to master conditional stats.

Always test the all-fail case.

Practice Strategy
  • MCQ Practice — verify the divisor matches the conditional count, not the array length.
  • Java Lab — write averagePositive, minPositive, averagePassing. Test with all-failing inputs.
  • FRQ Practice — guard division and minimum-find against the empty case explicitly.
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 05 Conditional Average and Minimum FRQ Practice

AP-style topic practice assessment

Start