Question 5
OCR Computer Science June 2024 Algorithms and problem solving (H046-02)AS13 marks
On the specification
- (a)
- 2.3 Algorithms
- (b)(i)
- 2.3 Algorithms
- (b)(ii)
- 2.2 Problem solving and programming
Question text
5 A program makes use of searching and sorting algorithms. (a) The following incomplete pseudocode algorithm uses a binary search to find the integer numberToFind in the array array. It returns the index of the array or –1 if the integer is not found. Complete the pseudocode algorithm. function binarySearch(array, ) lowerbound = 0 upperbound = array.length – 1 while true if(upperbound < lowerbound) then return else mid = (upperbound + lowerbound) if(array[mid] < numberToFind) then lowerbound = mid elseif(array[mid] > numberToFind) then upperbound = mid else return endif endif endwhile endfunction [6] (b) An array stores the following data: 20 8 33 16 (i) Describe how the given data will be sorted into descending numerical order using an insertion sort. You should refer to the data in this array throughout your answer. [5] (ii) The size of the array has now been increased to seven elements. The insertion sort algorithm needs to be tested to ensure it sorts a range of test data into descending numerical order. For example, the test data in the array here will test to see if the insertion sort will sort data in the opposite order. 12 3 4 5 6 7 Give two other different sets of data in the array that can be used to test the insertion sort and state the purpose of each set of test data. Each test needs to have a different purpose. Set One Test Data 1 Purpose of test data 1 Set Two Test Data 2 Purpose of test data 2 [2]