An automation script manages a system of three server nodes: Node 0, Node 1, and Node 2. To optimize task scheduling, the system periodically sorts the nodes based on their current active connection counts, which are stored in the array arr. At a particular time step, the connection counts are arr = [6, 9, 3].
The script uses the sorting algorithm shown in Figure 1 to sort the array in ascending order.
Figure 1
1 arr ← [6, 9, 3]
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
Complete the trace table below for this algorithm.
| arr[0] | arr[1] | arr[2] | sorted | i | t |
|---|---|---|---|---|---|
| 6 | 9 | 3 | 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.