Question 3
OCR Computer Science June 2022 Algorithms and problem solving (H046-02)AS10 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
Question text
3 Trudi would like to sort an array of numbers into order. The numbers before they have been sorted can be seen here. 89 25 75 37 45 (a) Trudi will use a bubble sort to put these numbers into order from smallest to largest. Show the first pass of the bubble sort. You should clearly show each comparison made. [4] (b) Trudi has written a procedure, bubbleSort. 1 procedure bubbleSort(numbers) 2 do 3 sorted = true 4 for count = 0 to numbers.length -2 5 if numbers[count] > numbers[count+1] then 6 temp = numbers[count+1] 7 numbers[count+1] = numbers[count] 8 numbers[count] = temp 9 sorted = false 10 endif 11 next count 12 until sorted == true 13 endprocedure (i) Identify a line in the procedure bubbleSort where a decision is taken. [1] (ii) Identify the name of the parameter used in the procedure bubbleSort. [1] (iii) Describe the purpose of the temp variable in the procedure bubbleSort. [2] (iv) Describe the purpose of the sorted variable in the procedure bubbleSort. [2]