Representing algorithms

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
Question 10
Medium

At the start of a cargo logistics process, four shipping containers labeled A, B, C, and D are arranged across three loading bays (0, 1, and 2).

Bay 0 has the four containers stacked vertically: container A at the bottom, B above it, C above B, and D on top. Bays 1 and 2 are empty.

Initial configuration of cargo bays

State the final arrangement of the containers in each bay after the following algorithm is executed:

WHILE HEIGHT(0) > 2
    MOVE(0, 1)
ENDWHILE
MOVE(1, 2)
MOVE(0, 1)

(Note: MOVE(X, Y) moves the top container from bay X to the top of the stack in bay Y, and HEIGHT(X) returns the number of containers currently in bay X.)

[3]

Representing algorithms Questions

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