Question 9
AQA Computer Science June 2018 Paper 1GCSE14 marks
On the specification
- 9.1
- 3.1 Fundamentals of algorithms3.2 Programming
- 9.2
- 3.2 Programming
- 9.3
- 3.2 Programming
- 9.4
- 3.1 Fundamentals of algorithms3.2 Programming
Question text
9 The following subroutines control the way that labelled blocks are placed in different columns. BLOCK_ON_TOP(column) returns the label of the block on top of the column given as a parameter. MOVE(source, destination) moves the block on top of the source column to the top of the destination column. HEIGHT(column) returns the number of blocks in the specified column. 9.1 This is how the blocks A, B and C are arranged at the start. Draw the final arrangement of the blocks after the following algorithm has run. MOVE(0, 1) MOVE(0, 2) MOVE(0, 2) [3 marks] 9.2 This is how the blocks A, B and C are arranged at the start. Draw the final arrangement of the blocks after the following algorithm has run. WHILE HEIGHT(0) > 1 MOVE(0, 1) ENDWHILE MOVE(1, 2) [3 marks] 9.3 This is how the blocks A, B and C are arranged at the start. Draw the final arrangement of the blocks after the following algorithm has run. FOR c 0 TO 2 IF BLOCK_ON_TOP(0) = 'B' THEN MOVE(0, (c+1) MOD 3) ELSE MOVE(0, (c+2) MOD 3) ENDIF ENDFOR This algorithm uses the MOD operator which calculates the remainder resulting from integer division. For example, 13 MOD 5 = 3. [3 marks] 9.4 Develop an algorithm using either pseudo-code or a flowchart that will move every block from column 0 to column 1. Your algorithm should work however many blocks start in column 0. You may assume there will always be at least one block in column 0 at the start and that the other columns are empty. The order of the blocks must be preserved. The MOVE subroutine must be used to move a block from one column to another. You should also use the HEIGHT subroutine in your answer. For example, if the starting arrangement of the blocks is: Then the final arrangement should have block B above block A: [5 marks]