60Medium
0/6

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]

Sorting algorithms Questions

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.

PreviousNext

Sorting algorithms Questions

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