Quelpr

CAPE Computer Science Unit 2 · 2013 · Paper 2 · Question 2(a)(i)

Given a C function `bubbleSort(int a[], int numItems)` implementing bubble sort on an array of integers.

Explain the purpose of the outer 'for' loop.

The mark scheme is shown once you've answered.

Practise this question

Other parts of this question

  1. 2(a)(ii)Explain carefully the process occurring in the inner 'for' loop.[3 marks]
  2. 2(a)(iii)State why the upper limit for j in the inner 'for' loop is (numItems - i) rather than (numItems).[1 mark]
  3. 2(a)(iv)a)Given the array a with 5 values: [5, 1, 4, 8, 2], show the contents of the array after each stage during the FIRST pass of the bubble sort.[4 marks]
  4. 2(a)(iv)b)Show the contents of the array at the end of the SECOND and THIRD passes of the bubble sort.[2 marks]
  5. 2(b)An array contains 7 integers: [34, 5, 10, 1, 9, 23, 14]. Using the selection sort algorithm, show the array contents after each of the first four passes.[4 marks]
  6. 2(c)Describe the principles behind binary search when searching for an item in an array.[6 marks]
  7. 2(d)(i)How many comparisons does a linear search make before determining that 50 is not present in the array?[1 mark]
  8. 2(d)(ii)How many comparisons does a binary search make before determining that 50 is not present in the array? Show your working.[2 marks]

More practice: the rest of this paper · more Searching and Sorting Algorithms questions · all CAPE Computer Science Unit 2 past papers