Complete the trace table for the algorithm shown in Figure 1. Some values have already been entered.
Figure 1
1 list ← [5, 4, 6]
2 sorted ← false
3 WHILE sorted = false
4 sorted ← true
5 i ← 0
6 WHILE i < 2
7 IF list[i] > list[i+1] THEN
8 temp ← list[i]
9 list[i] ← list[i+1]
10 list[i+1] ← temp
11 sorted ← false
12 ENDIF
13 i ← i + 1
14 ENDWHILE
15 ENDWHILE
sorted | i | temp | list[0] | list[1] | list[2] |
|---|---|---|---|---|---|
false | 5 | 4 | 6 | ||
true | 0 | ||||
| 5 | 4 | 5 | |||
52 exam-style questions on AQA GCSE Computer Science Sorting algorithms. Each one has a worked solution and a mark scheme showing where the marks go.