Question 4
OCR Computer Science November 2020 Paper 2A level20 marks
On the specification
- (a)
- 2.2 Problem solving and programming
- (b)
- 2.3 Algorithms
- (c)
- 2.3 Algorithms
- (d)
- 2.3 Algorithms
Question text
4 The following pseudocode procedure performs an insertion sort on the array parameter. 1 procedure insertionSort(dataArray:byRef) 2 for i = 1 to dataArray.Length - 1 3 temp = dataArray[i] 4 tempPos = i – 1 5 exit = false 6 while tempPos >= 0 and exit == false 7 if dataArray[tempPos] < temp then 8 dataArray[tempPos + 1] = dataArray[tempPos] 9 tempPos = tempPos - 1 10 else 11 exit = true 12 endif 13 endwhile 14 dataArray[tempPos + 1] = temp 15 next i 16 endprocedure (a) Explain why dataArray is passed by reference and not by value. [2] (b) State whether the procedure insertionSort sorts the data into ascending or descending order and explain your choice. [3] (c)* Two other sorting algorithms are merge sort and quick sort. Compare the use of merge sort, quick sort and insertion sort on an array with a small number of elements, and on an array with a very large number of elements. You should make reference to the time complexities of each algorithm using the Big O notation in your answer. [9] (d) A fourth sorting algorithm is a bubble sort. Describe how a bubble sort will sort an array of 10 elements. [6]