Skip to content

Course home

Sorting algorithms

Sorting algorithms

EasyMediumHard
123456789101112131415161718192021222324252627
Question 25

A telemetry logging system for an autonomous underwater vehicle (AUV) records three depth readings (in meters): [9, 4, 6]. To prepare these readings for a calibration report, they must be sorted in ascending order. The system uses the bubble sort variant shown below:

1  arr ← [9, 4, 6]
2  swapped ← true
3  WHILE swapped = true
4      swapped ← false
5      index ← 0
6      WHILE index < 2
7          IF arr[index] > arr[index + 1] THEN
8              temp ← arr[index]
9              arr[index] ← arr[index + 1]
10             arr[index + 1] ← temp
11             swapped ← true
12         ENDIF
13         index ← index + 1
14     ENDWHILE
15 ENDWHILE

Complete the trace table below to show how the variables and array elements change during the execution of the algorithm.

swappedindextemparr[0]arr[1]arr[2]
true946
false0
949
true
1
969
2
[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