Question 3

OCR Computer Science June 2022 Algorithms and programming (H446-02)A level22 marks

On the specification

(a)
1.4 Data types, data structures and algorithms
(b)
2.3 Algorithms
(c)
2.3 Algorithms
(d)
2.3 Algorithms
Question text

3 A bubble sort will sort an array of 50 integer values called numberArray. (a) State why the integer values are stored in an array instead of separate variables. [1] (b) This bubble sort algorithm is written to sort numberArray into ascending numerical order. Complete this bubble sort algorithm. arrayLength = tempValue = 0 do flag = false for y = 0 to arrayLength - if numberArray[y] > numberArray[y + 1] then = numberArray[y] numberArray[ ] = numberArray[y + 1] numberArray[y + 1] = flag = true endif next y until flag == false [5] (c) One section of numberArray is shown here. 2 12 1 9 3 5 15 7 A second sorting algorithm that could be used to sort this data is a merge sort. Show how a merge sort will sort this section of the array numberArray into ascending numerical order. [4] (d)* Another sorting algorithm is insertion sort. The number of values stored in the array numberArray has been reduced to 10. Compare the use of bubble, merge and insertion sorts on the array numberArray. You should include the following in your answer: • how each algorithm works • the Big O complexities for each algorithm • the suitability of each algorithm for sorting the 10 values. [12]