Question 12
AQA Computer Science June 2022 Paper 1B (8525/1B)GCSE14 marks
On the specification
- 12.1
- 3.1 Fundamentals of algorithms3.2 Programming
- 12.2
- 3.1 Fundamentals of algorithms
- 12.3
- 3.2 Programming
Question text
12 Figure 13 shows an algorithm represented in pseudo-code. A developer wants to box check the algorithm works correctly. • Line numbers are included but are not part of the algorithm. Figure 13 1 arr[0] 'c' 2 arr[1] 'b' 3 arr[2] 'a' 4 FOR i 0 TO 1 5 FOR j 0 TO 1 6 IF arr[j + 1] < arr[j] THEN 7 temp arr[j] 8 arr[j] arr[j + 1] 9 arr[j + 1] temp 10 ENDIF 11 ENDFOR 12 ENDFOR 12.1 Complete the trace table for the algorithm shown in Figure 13. box Some values have already been entered. You may not need to use all the rows in the table. [6 marks] arr i j temp [0] [1] [2] c b a 12.2 State the purpose of the algorithm. [1 mark] 12 3 box . Figure 13 has been included again below. Figure 13 1 arr[0] 'c' 2 arr[1] 'b' 3 arr[2] 'a' 4 FOR i 0 TO 1 5 FOR j 0 TO 1 6 IF arr[j + 1] < arr[j] THEN 7 temp arr[j] 8 arr[j] arr[j + 1] 9 arr[j + 1] temp 10 ENDIF 11 ENDFOR 12 ENDFOR An earlier attempt at writing the algorithm in Figure 13 had different code for lines 4 and 5. Lines 4 and 5 of the pseudo-code were: FOR i 0 TO 2 FOR j 0 TO 2 Explain why the algorithm did not work when the value 2 was used instead of the value 1 on these two lines. [1 mark]