Representing algorithms

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
Question 13
Medium

An array represents the status of a sequence of 7 weather sensors along a mountain trail. Each sensor can be either active (A) or idle (I).

Subroutines

SubroutineExplanation
INVERT(n)If the sensor at index nnn is A, it is set to I. If it is I, it is set to A.
COPY_LST(n)The sensor at index nnn is set to the same status as the sensor at index (n−1n - 1n−1).
RESET_RANGE(m, n)All sensors between index mmm and index nnn (but not including mmm and nnn) are set to I.

Initial State

0123456
IAAIAII

What will the array of sensors become after the following algorithm is executed?

p ← 2
INVERT(p + 2)
COPY_LST(p - 1)
INVERT(p + 1)

Write your final answer in the table below:

0123456
[3]

Representing algorithms Questions

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