Unit 4 Cycle 2 Day 27: Comprehensive: Counting Ascending Steps
Share
Comprehensive: Counting Ascending Steps
Section Mixed — Review: All Unit 4
Key Concept
Counting ascending steps in an array identifies positions where each element is greater than its predecessor. The algorithm compares arr[i] to arr[i - 1] (starting from index 1) and increments a counter when the current element is larger. This is a variation of the adjacent comparison pattern. The AP exam may extend this to finding the longest ascending subsequence, counting descending steps, or identifying all peak elements (greater than both neighbors). Each variation requires slight modifications to the comparison logic.
Consider the following code segment.
What is printed?
Answer: (A) 4
Ascending pairs: (3,5), (1,9), (2,7), (4,6). Count = 4.
Why Not the Others?
(B) Only 4 pairs are ascending.
(C) Missing one ascending pair.
(D) 8 is total comparisons, not ascending count.
Common Mistake
Counting ascending steps: compare arr[i] with arr[i-1]. Start loop at 1. Count when current > previous.
AP Exam Tip
Adjacent-pair counting: loop from 1, compare with previous. Counts properties of consecutive pairs.