Skip to content

Course home

Representing algorithms

Representing algorithms

EasyMediumHard
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
Question 15

In a digital document archiving facility, a robotic arm is used to manage vertical stacks of historical document folders.

There are three archiving trays: Tray X, Tray Y, and Tray Z.

Develop an algorithm, using either pseudo-code or a flowchart, that will transfer all document folders from Tray X to Tray Z.

Your algorithm must work regardless of how many folders are initially stacked in Tray X. You can assume there is always at least one folder in Tray X at the start, and that Tray Y and Tray Z are completely empty.

The vertical order of the folders must be preserved in the final stack on Tray Z (i.e. the folder that starts at the top of the stack in Tray X must end up at the top of the stack in Tray Z).

You must use only the following subroutines in your solution:

  • TRANSFER_FOLDER(source, destination): Moves the top folder from the source tray and places it on top of the stack in the destination tray.
  • COUNT_FOLDERS(tray): Returns the number of folders currently stacked in the specified tray.

For example, if the starting arrangement is:

  • Tray X: Folder [1] (at the bottom), Folder [2] (on top of Folder [1])
  • Tray Y: Empty
  • Tray Z: Empty

Then the final arrangement must have Folder [2] stacked on top of Folder [1] in Tray Z, with Tray X and Tray Y being empty.

[5]
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