Question 1

OCR Computer Science June 2023 Algorithms and problem solving (H046-02)AS15 marks

On the specification

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

1 A program uses a bubble sort to sort data into ascending numerical order. The data is stored in a 0-indexed 1-dimensional array. (a) Show each stage of a bubble sort to sort this data into ascending numerical order: 15 3 9 2 7 You should clearly show and label each pass in your answer. [4] (b) A programmer has partially developed a bubble sort algorithm in pseudocode. This will partially sort an array of numbers called numbers that is passed as a parameter. 1 procedure bubbleSort(numbers : byRef) 2 flag = true 3 for x = 0 to numbers.length – 1 4 if numbers[x] > numbers[x + 1] then 5 holdValue = numbers[x] 6 numbers[x] = numbers[x + 1] 7 numbers[x + 1] = holdValue 8 flag = false 9 endif 10 next x 11 endprocedure (i) Explain why the procedure bubbleSort accepts the array numbers by reference and not by value. [3] (ii) The programmer has used a for loop on line 3 in the procedure bubbleSort. A for loop is a count controlled loop. State what is meant by the term ‘count controlled loop’. [1] (iii) State the purpose of the variable holdValue in the procedure bubbleSort. [3] (iv) The procedure bubbleSort will only partially sort the array numbers into order. Describe what the programmer would need to add to the algorithm to enable it to fully sort the numbers into order. [2] (c) (i) The array numbers contains 356 numbers to be sorted by the bubble sort algorithm. State the maximum number of passes a bubble sort would need to complete to sort 356 numbers into order. [1] (ii) State the name of one other sorting algorithm. [1]