An algorithm is designed to sort a list of three elements in descending order.
Complete the trace table for this algorithm shown in Figure 1.
Some values have already been entered. You may not need to use all the rows in the table.
1 A[0] ← 5
2 A[1] ← 14
3 A[2] ← 9
4 FOR p ← 0 TO 1
5 FOR q ← 0 TO 1
6 IF A[q + 1] > A[q] THEN
7 hold ← A[q]
8 A[q] ← A[q + 1]
9 A[q + 1] ← hold
10 ENDIF
11 ENDFOR
12 ENDFOR
| A[0] | A[1] | A[2] | p | q | hold |
|---|---|---|---|---|---|
| 5 | 14 | 9 | |||
208 exam-style questions on AQA GCSE Computer Science Representing algorithms. Each one has a worked solution and a mark scheme showing where the marks go.