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 | ||
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.