Representing algorithms

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
Question 14
Easy

An embedded systems engineer is designing a low-power algorithm to count the number of "rising edges" in a discrete time-series sensor signal. A rising edge is defined as a transition where a sensor reading is strictly greater than the immediately preceding reading, as shown in the diagram below:

Discrete time-series sensor signal diagram with rising edges labeled

The signal is stored in a 0-indexed array called sensor_readings. The engineer drafts the following pseudocode algorithm to compute this:

rising_edges ← 0
i ← 0
WHILE i < LEN(sensor_readings) - L1
    IF sensor_readings[i] < sensor_readings[i + 1] THEN
        rising_edges ← rising_edges + 1
    ENDIF
    i ← i + 1
ENDWHILE

To ensure the algorithm correctly processes all adjacent sample pairs without causing an "out-of-bounds" index error, what integer value must be substituted for L1?

000

111

222

−1-1−1

Representing algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Representing algorithms