Question 3
OCR Computer Science June 2023 Computational thinking, algorithms and programming (J277-02)GCSE8 marks
On the specification
- (a)
- 2.1 Algorithms
- (b)
- 2.1 Algorithms2.2 Programming fundamentals
- (c)(i)
- 2.1 Algorithms
- (c)(ii)
- 2.1 Algorithms
Question text
3 An insertion sort is one type of sorting algorithm. A student has written a pseudocode algorithm to perform an insertion sort on a 1D array names. names = ["Kareem", "Sarah", "Zac", "Sundip", "Anika"] for count = 1 to names.length – 1 pos = count while (pos > 0 and names[pos] < names[pos – 1]) temp = names[pos] names[pos] = names[pos – 1] names[pos – 1] = temp pos = pos – 1 endwhile next count (a) Describe the purpose of the variable temp in the insertion sort pseudocode algorithm. [2] (b) An insertion sort contains a nested loop; a loop within a loop. In this pseudocode algorithm the outer loop is a count-controlled loop and the inner loop is a condition-controlled loop. Explain why the inner loop needs to be a condition-controlled loop. [2] (c) A bubble sort is another type of sorting algorithm. (i) Describe one difference between an insertion sort and a bubble sort. [2] (ii) Describe two similarities between an insertion sort and a bubble sort. 1 2 [2]