An automated sorting system sorts three parcels by their weights (in kg) in descending order to balance a drone's payload. The weights are stored in an array w w\,w of size 3, initially containing [4,1,9][4, 1, 9][4,1,9].
The system uses the algorithm shown in Figure 1.
Figure 1
1 w ← [4, 1, 9]
2 sorted ← false
3 WHILE sorted = false
4 sorted ← true
5 i ← 0
6 WHILE i < 2
7 IF w[i+1] > w[i] THEN
8 t ← w[i]
9 w[i] ← w[i+1]
10 w[i+1] ← t
11 sorted ← false
12 ENDIF
13 i ← i + 1
14 ENDWHILE
15 ENDWHILE
Complete the trace table for this algorithm.
| w[0] | w[1] | w[2] | sorted | i | t |
|---|---|---|---|---|---|
| 4 | 1 | 9 | false | ||
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.