Question 2
AQA Computer Science June 2019 Paper 1AS8 marks
On the specification
- 2.1
- 3.4 Theory of computation
- 2.2
- 4.3 Fundamentals of algorithms
Question text
2 The algorithm, represented using pseudo-code in Figure 1, describes a method to rearrange three numbers in a data structure. Figure 1 Numbers[0] ← 43 Numbers[1] ← 17 Numbers[2] ← 85 FOR x ← 1 TO 2 MyValue ← Numbers[x] y ← x – 1 WHILE (y > -1) AND (Numbers[y] < MyValue) Numbers[y + 1] ← Numbers[y] y ← y - 1 ENDWHILE Numbers[y + 1] ← MyValue ENDFOR 2.1 Complete Table 1 by hand-tracing the algorithm in Figure 1. You may not need to use all the rows in Table 1. Table 1 Numbers[y] Numbers y > -1 < MyValue ? x MyValue y Numbers[y] ? (True/ [0] [1] [2] (True/ False) False) 43 17 85 Copy the contents of all the unshaded cells in Table 1 into your Electronic Answer Document. [4 marks] 2.2 What type of rearrangement does this algorithm perform? [1 mark]