Representing algorithms

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
Question 26
Medium

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]

Representing algorithms Questions

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