1Easy
0/1

An earlier attempt at writing a bubble sort algorithm to sort meteorological pressure readings in a telemetry system shown in the pseudo-code below had different code for lines 7 and 8.

1  pressure[0] ← 1013
2  pressure[1] ← 950
3  pressure[2] ← 850
4  pressure[3] ← 700
5  pressure[4] ← 500
6  pressure[5] ← 300
7  FOR i ← 0 TO 4
8      FOR j ← 0 TO 4
9          IF pressure[j + 1] > pressure[j] THEN
10             temp ← pressure[j]
11             pressure[j] ← pressure[j + 1]
12             pressure[j + 1] ← temp
13         ENDIF
14     ENDFOR
15 ENDFOR

Lines 7 and 8 of the pseudo-code were originally written as:

7  FOR i ← 0 TO 5
8      FOR j ← 0 TO 5

Explain why the algorithm would result in a runtime error when the value 5 was used instead of the value 4 on these two lines.

[1]

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.

Next

Sorting algorithms Questions

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