Complete the trace table for the algorithm shown in Figure 1 which sorts a list of three elements in descending order.
Some values have already been entered. You may not need to use all the rows in the table.
1 arr[0] ← 2
2 arr[1] ← 7
3 arr[2] ← 9
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
| arr | i | j | temp | ||
|---|---|---|---|---|---|
| [0] | [1] | [2] | |||
| 2 | 7 | 9 | |||
Practise AQA GCSE Computer Science Sorting algorithms with exam-style questions for GCSE Computer Science. 62 questions, matched to the AQA GCSE Computer Science (8525) specification and written in Paper 1 and Paper 2 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.