Question 1
1 markA binary search is used on an array of 16 items with indexes 0 to 15. The index of the middle item is worked out with this line of pseudo-code, where low and high are the first and last indexes still being searched:
mid ← (low + high) DIV 2Which index is checked first?
Choose your answer.
- 7
- 8
- 7.5
- 15
Model answer
7
Explanation
At the start low is 0 and high is 15, so mid is 15 DIV 2, which is 7 because DIV gives the whole-number part of the division. 7.5 comes from real division, which cannot be used as an index. 8 is the other central item, which this line of code does not pick.
Mark scheme
-
1 mark
7
If more than one option is given, 0 marks. Mark is for AO2 (apply).