Skip to content

Course home

Representing algorithms

Representing algorithms

EasyMediumHard
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
Question 65

An automated facility security corridor controls a row of 7 heavy security gates, indexed 0 to 6.

The subroutines in the table below are used to control the state of the gates, switching them between locked and unlocked.

SubroutineExplanation
FLIP(n)If the gate at index n is locked it is set to unlocked. If it is unlocked it is set to locked.
DUPLICATE(n)If the gate at index (n - 1) is locked, the gate at index n is set to locked. If the gate at index (n - 1) is unlocked, the gate at index n is set to unlocked.
RELEASE_BETWEEN(m, n)All gates strictly between index m and index n (but not including m and n) are set to unlocked.

If the starting array of gates is:

0123456
lockedlockedlockedlockedlockedlockedlocked

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

0123456
unlockedunlockedunlockedunlockedunlockedunlockedunlocked

You must use each of the subroutines FLIP, DUPLICATE and RELEASE_BETWEEN exactly once in your answer.

[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