An array represents the state of a strip of 7 smart LED indicators. The indicators can be either red or blue.
| Subroutine | Explanation |
|---|---|
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. |
| 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| blue | red | blue | red | red | blue | red |
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:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|
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.