Question 3

OCR B (MEI) Further Maths June 2018 Modelling with algorithms (Y413-01)AS7 marks

On the specification

(i)
A1–A11 Modelling with Algorithms (Y413): Algorithms
(ii)
A1–A11 Modelling with Algorithms (Y413): Algorithms
(iii)
A1–A11 Modelling with Algorithms (Y413): Algorithms
Question text

3 A list of n numbers is sorted by making passes through an algorithm as follows. The first pass consists of the following. Compare the first number and second number. If necessary, swap them so that the first number is less than or equal to the second number. The second pass consists of the following. Compare the second number and third number. If necessary, swap them so that the second number is less than or equal to the third number. If a swap occurred compare the new second number and the first number. If necessary, swap them so that the first number is less than or equal to the second number. The ^n-1hth (final) pass consists of the following. Compare the ^n-1hth number and nth number. If necessary, swap them so that the ^n-1hth number is less than or equal to the nth number. If a swap occurred compare the new ^n-1hth number and the ^n-2hth number. If necessary, swap them so that the ^n-2hth number is less than or equal to the ^n-1hth number. Continue in this way until no swap occurs between consecutive numbers or the first number has been swapped with the second number. (i) Sort the following list of six numbers using the above algorithm 12 34 15 23 10 25 You should only show the result at the end of each pass. [2] The algorithm is now applied to a list of n numbers. (ii) Find, when n = 6, • the minimum possible number of comparisons needed, • the maximum possible number of comparisons needed. [2] The number of comparisons is used as a measure of the complexity of the above algorithm. (iii) Determine, in the worst case, the complexity of the algorithm in terms of n. [3]