Question 1
A programmer needs to sort an array of numeric data using an insertion sort.
The following, incomplete, algorithm performs an insertion sort.
Complete the algorithm.
[3]
Show how an insertion sort would sort the following data:
[6]
Using Big-O notation state the best case complexity of insertion sort.
[1]
Explain what your answer to part (b)(i) means.
[3]
(c*) The number of data items in the array is continually increasing.
Insertion sort has a worst case time complexity of O(n2) and space complexity of O(1).
An alternative sorting algorithm that could be used is bubble sort which also has a worst case time complexity of O(n2) and space complexity of O(1).
Briefly outline how the bubble sort algorithm works. Discuss the relationship between the complexities and the two sorting algorithms and justify which of the two algorithms is best
suited to sorting the array.
[9]