Worked solution from the Computational thinking and Problem-solving Paper 3 Advanced Theory booklet, Part 1 of 2.
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]
Write:
The list must be ordered (sorted) [1]
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).
Write:
As the number of items increases, the time to search increases [1]
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]
▶ 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.