Skip to content

Course home

Sorting algorithms

Sorting algorithms

EasyMediumHard
123456789101112131415161718192021222324252627
Question 26

An algorithm is shown below in pseudocode. It operates on an array named items containing three elements.

1  items ← [5, 2, 7]
2  sorted ← false
3  WHILE sorted = false
4      sorted ← true
5      idx ← 0
6      WHILE idx < 2
7          IF items[idx+1] > items[idx] THEN
8              temp ← items[idx]
9              items[idx] ← items[idx+1]
10             items[idx+1] ← temp
11             sorted ← false
12         ENDIF
13         idx ← idx + 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).

sortedidxtempitems[0]items[1]items[2]
527
false
true0
1
272
(a)2
true0
(b)(c)5
(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