9618/32/M/J/22 question 8: worked solution (May/June 2022, paper 32)
Show as plain textHide plain text
Cambridge A2 Level Computer Science 9618 · 19.1 Algorithms Worked solution from the Computational thinking and Problem-solving Paper 3 Advanced Theory booklet, Part 1 of 2. Q4 9618/32/M/J/22 original Q8 Structured · 13 marks 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 IDEA A 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 VIDEO ▶ Whole paper Video solution of the whole paper · by qiphyedu. Tap the picture to open it on YouTube.