Skip to content

Course home

Sorting algorithms

Sorting algorithms

EasyMediumHard
123456789101112131415161718192021222324252627
Question 27

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]sortedit
693false
[6]
Markscheme

Sorting algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Sorting algorithms

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.

Question bank