Skip to content

Course home

Representing algorithms

Representing algorithms

EasyMediumHard
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
Question 40

An array represents the state of a strip of 7 smart LED indicators. The indicators can be either red or blue.

Subroutines

SubroutineExplanation
FLIP(n)If the LED at index n n\,n is red, it is set to blue. If it is blue, it is set to red.
COPY_NXT(n)The LED at index n n\,n is set to the same colour as the LED at index (n+1n + 1n+1).
CLEAR_BETWEEN(m, n)All the LEDs between index m m\,m and index nnn (but not including m m\,m and nnn) are set to blue.

Initial State

0123456
blueredblueredredbluered

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

k ← 3
FLIP(k)
COPY_NXT(k - 2)
FLIP(k + 2)

Write your final answer in the table below:

0123456
[3]
Markscheme

Representing algorithms Questions

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

208 exam-style questions on AQA GCSE Computer Science Representing algorithms. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank