Cambridge A2 Level Computer Science 9618 · 19.1 Algorithms

Q4 · 9618/32/M/J/22 Q8

Worked solution from the Computational thinking and Problem-solving Paper 3 Advanced Theory booklet, Part 1 of 2.

Q49618/32/M/J/22original Q8Structured · 13 marks
Question 8 from 9618/32/M/J/22

Worked solution

(a)

Fill each gap:

DECLARE ValueToFind : INTEGER
MaxIndex ← 9
Index ← Index + 1
OUTPUT "Value not found"

ValueToFind declared as INTEGER [1]

MaxIndex ← 9 (or LENGTH(MyList) - 1) [1]

Index ← Index + 1 [1]

OUTPUT a message such as "Value not found" [1]

(b)(i)

Write:

The list must be ordered (sorted) [1]

(b)(ii)

Write any four of these steps:

Find the middle item (or index) of the list [1]

Compare the middle item with the value being searched for [1]

If they are equal, the item has been found [1]

If not, discard the half of the list that cannot hold the item (keep the upper half if the middle is smaller, the lower half if it is larger) [1]

Repeat until the item is found, or only one item is left and it does not match (any four of these points score).

(b)(iii)

Write:

As the number of items increases, the time to search increases [1]

(c)

Compare the two:

Linear search is O(n) and binary search is O(log n) [1]

Linear search time rises in step with the number of items, while binary search time rises logarithmically [1]

So binary search time grows more slowly, and linear search time grows faster [1]

KEY IDEAA linear search checks each item (O(n)) but a binary search halves a sorted list each time (O(log n)).
TOTAL 13 marks

Official mark scheme

Mark scheme for 9618/32/M/J/22 question 8
VIDEO
▶ Whole paper

Video solution of the whole paper · by qiphyedu. Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.