61Medium
0/6

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]

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