Skip to content

Course home

Representing algorithms

Representing algorithms

EasyMediumHard
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
Question 72

An automated greenhouse irrigation system controls a row of 7 watering valves, indexed 0 to 6.

The subroutines in the table below are used to control the state of the valves, switching them between active and inactive.

SubroutineExplanation
TOGGLE(n)If the valve at index n is active it is set to inactive. If it is inactive it is set to active.
COPY(n)If the valve at index (n - 1) is active, the valve at index n is set to active. If the valve at index (n - 1) is inactive, the valve at index n is set to inactive.
CLEAR_BETWEEN(m, n)All valves strictly between index m and index n (but not including m and n) are set to inactive.

If the starting array of valves is:

0123456
activeactiveactiveactiveactiveactiveactive

Write an algorithm, using exactly three subroutine calls, that means the final array of valves will be:

0123456
inactiveinactiveinactiveinactiveinactiveinactiveinactive

You must use each of the subroutines TOGGLE, COPY and CLEAR_BETWEEN exactly once in your answer. If you do not do this you may still be able to get some marks.

[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