Question 9
OCR Computer Science Specimen Paper 2A level6 marks
On the specification
- (a)
- 2.3 Algorithms
- (b)
- 2.3 Algorithms
- (c)
- 2.3 Algorithms
Question text
9 Linear search and binary search are two different algorithms which can be used for searching arrays. When comparing linear and binary search it is possible to look at the best, worst and average number of items in the array that need to be checked to find the item being searched for. Assume every item in the array is equally likely to be searched for. (a) Complete the table below Worst Case Average Case Best Case number of searches Binary Search log2(n)-1 Linear Search n/2 (b) As the size of an array increases the average number of checks grows logarithmically. State what is meant by logarithmic growth. [1] (c) Assuming an array is sorted give a situation when a linear search would perform better than a binary search. [1]