Complete the trace table for the algorithm shown in Figure 1. Some values have already been entered.
Figure 1
1 list ← [3, 8, 2]
2 changed ← false
3 WHILE changed = false
4 changed ← true
5 i ← 0
6 WHILE i < 2
7 IF list[i+1] > list[i] THEN
8 temp ← list[i]
9 list[i] ← list[i+1]
10 list[i+1] ← temp
11 changed ← false
12 ENDIF
13 i ← i + 1
14 ENDWHILE
15 ENDWHILE
changed | i | temp | list[0] | list[1] | list[2] |
|---|---|---|---|---|---|
false | 3 | 8 | 2 | ||
true | 0 | ||||
| 3 | 8 | 3 | |||
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.