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