The same QuickSort algorithm from the previous question (pivot always chosen as list[0]) is now applied to a list that is already sorted in ascending order: [2, 5, 7, 9, 12, 15] (6 elements).
(a)State the pivot, and the resulting less and greaterEq lists, for the first call QuickSort([2, 5, 7, 9, 12, 15]).(2)
(b)Explain why, for this sorted input with this pivot-choice strategy, every recursive call will produce an empty less list and a greaterEq list containing all of the remaining elements.(2)
(c)Complete the table below showing the number of element-to-pivot comparisons made at each level of recursion, continuing until the list is fully sorted, and state the total number of comparisons made overall.
| level | list size at this level | comparisons made |
|---|
| 1 | 6 | 5 |
| 2 | 5 | |
| 3 | 4 | |
| 4 | 3 | |
| 5 | 2 | |
| 6 | 1 | |
(3)
(d)Show that, in general, this worst-case total number of comparisons for a sorted list of n elements is n(n - 1) / 2, and state the resulting Big O time complexity.(3)
(e)State two different strategies for choosing the pivot that would make this particular worst-case scenario (an already-sorted list) far less likely to occur in practice.(2)
(Total for Question 6 is 12 marks)