Complete the trace table for the algorithm shown in Figure 1.
Figure 1
1 arr ← [5, 8, 2]
2 sorted ← false
3 WHILE sorted = false
4 sorted ← true
5 i ← 0
6 WHILE i < 2
7 IF arr[i+1] < arr[i] THEN
8 t ← arr[i]
9 arr[i] ← arr[i+1]
10 arr[i+1] ← t
11 sorted ← false
12 ENDIF
13 i ← i + 1
14 ENDWHILE
15 ENDWHILE
| arr[0] | arr[1] | arr[2] | sorted | i | t |
|---|---|---|---|---|---|
| 5 | 8 | 2 | false | ||
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.