Question 1

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

On the specification

(a)(i)
2.3 Algorithms
(a)(ii)
2.3 Algorithms
(b)
2.3 Algorithms
(c)(i)
2.2 Problem solving and programming2.3 Algorithms
(c)(ii)
2.2 Problem solving and programming
(c)(iii)
2.3 Algorithms
(c)(iv)
2.2 Problem solving and programming2.3 Algorithms
(c)(v)
2.2 Problem solving and programming2.3 Algorithms
Question text

1 Data in a computer program needs to be sorted. (a) (i) Describe the steps a bubble sort will take to sort items into ascending order. [5] (ii) Darcie and Felix have both written a program that will perform a bubble sort to put these numbers into ascending order. 21 3 4 5 6 7 Darcie’s version will complete six passes. However, Felix’s version will only need to complete two passes. Explain how Felix may have made his version more efficient than Darcie’s version. [2] (b) A second type of sorting algorithm is an insertion sort. Describe how an insertion sort can be used to put the following data into ascending order. 20 8 15 36 [5] (c) A third type of sorting algorithm is a quick sort. The following quick sort algorithm is made up of two functions called partition() and quickSort(). The algorithm will sort an integer array into ascending numerical order. 1 function partition(array, low, high) 2 pivot = array[high] 3 index = low - 1 4 for count = low to high-1 5 if array[count] < pivot then 6 index = index + 1 7 temp = array[index] 8 array[index] = array[count] 9 array[count] = temp 10 endif 11 next count 12 temp = array[index + 1] 13 array[index + 1] = array[high] 14 array[high] = temp 15 return index + 1 16 endfunction 17 18 function quickSort(array, low, high) 19 if low < high then 20 partitionIndex = partition(array, low, high) 21 quickSort(array, low, partitionIndex - 1) 22 quickSort(array, partitionIndex + 1, high) 23 endif 24 endfunction (i) Identify which of the two functions is recursive and give all of the line numbers where recursive calls are made. Recursive function name Recursive call line numbers [2] (ii) Identify the type of iteration used in the function partition(). [1] (iii) Describe the role of the function partition() in the quick sort algorithm. [3] (iv) The algorithm needs to be changed to sort the integer array into descending numerical order. Identify the line number that needs to be changed and write the amended line of code. Line number Amended line of code [2] (v) The quick sort is an example of a divide-and-conquer algorithm. Describe what divide-and-conquer means. [2]