Skip to content

Course home

Sorting algorithms

Sorting algorithms

EasyMediumHard
123
Question 1

A microcontroller in a smart thermostat sorts temperature readings to help analyze temperature ranges. The following algorithm is designed to sort three sensor readings stored in the array temps in ascending order.

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

Complete the trace table for the execution of this algorithm by identifying the values that should replace the letters (a), (b), (c), (d), (e), and (f).

sorteditemptemps[0]temps[1]temps[2]
493
false
true0
1
939
(a)2
true0
(b)(c)4
(d)1
(e)
true0
1
(f)
[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