Skip to content

Course home

Representing algorithms

Representing algorithms

EasyMediumHard
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
Question 85

Develop an algorithm using either pseudo-code or a flowchart that will move every cargo container from Bay 0 to Bay 2.

Your algorithm must work regardless of how many containers are initially stacked in Bay 0. You can assume there will always be at least one container in Bay 0 at the start, and that Bay 1 and Bay 2 are completely empty.

The vertical order of the containers must be preserved in the final stack.

You must use the following subroutines in your solution:

  • MOVE_CONTAINER(source, destination): Moves the top container from the source bay and places it on top of the stack in the destination bay.
  • GET_HEIGHT(bay): Returns the number of containers currently stacked in the specified bay.

For example, if the starting arrangement is:

  • Bay 0: Container [A] (at the bottom), Container [B] (on top of A)
  • Bay 1: Empty
  • Bay 2: Empty

Then the final arrangement should have Container [B] stacked on top of Container [A] in Bay 2, with Bay 0 and Bay 1 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