AP CSA Unit 4.5: Find Maximum Algorithm Practice

Unit 4, Section 4.5
Day 5 Practice • January 11, 2026
🎯 Focus: Array Algorithms - Find Maximum

Practice Question

Consider the following code segment:
int[] arr = {3, 7, 2, 9, 4};
int max = arr[0];

for (int i = 1; i < arr.length; i++) {
    if (arr[i] > max) {
        max = arr[i];
    }
}

System.out.println(max);
What is printed as a result of executing this code segment?

What This Tests: Section 4.5 covers array algorithms. The find-maximum pattern starts with the first element as the assumed max, then compares each subsequent element, updating max when a larger value is found.

Step-by-Step Trace

i arr[i] arr[i] > max? max
- - Initial 3
1 7 7 > 3? Yes 7
2 2 2 > 7? No 7
3 9 9 > 7? Yes 9
4 4 4 > 9? No 9

The Find-Max Pattern

// Standard find-maximum pattern:
int max = arr[0];           // 1. Start with first element
for (int i = 1; i < arr.length; i++) {  // 2. Start loop at index 1
    if (arr[i] > max) {      // 3. Compare each element
        max = arr[i];        // 4. Update if larger
    }
}

Common Mistakes

Mistake: Answer A (3)

This is the FIRST element, not the maximum. The algorithm finds that 9 is larger than all other elements.

Mistake: Answer C (4)

This is the LAST element, not the maximum. The algorithm doesn't just return the last value—it tracks the largest seen.

Related Algorithms

Similar Patterns

Find minimum: Change > to <

Find index of max: Track maxIndex instead of max

Count occurrences: Use == and increment counter

Difficulty: Medium • Time: 3 minutes • AP Skill: 2.D - Array algorithms

Ready to Level Up Your AP CSA Skills?

Get personalized help or access our complete question bank

Premium Question Bank - Coming Soon Schedule 1-on-1 Tutoring
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.