
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

Data Structures and Algorithms
Quicksort can be described as a recursive in-place sorting algorithm that performs a partition() operation on the given array and then invokes itself twice on two distinct subranges of the array.
(a) Describe the purpose, I/O parameters and effect of the partition() procedure and explain what the pivot is. Pseudocode is not required. [3 marks]
(b) Give pseudocode for the quicksort() procedure that would call the partition() procedure you described in (a). Prove that your quicksort() will always terminate. [3 marks]
(c) Analyse the worst-case behaviour of Quicksort and discuss possible ways of improving it. [4 marks]
(d ) Some researchers have suggested choosing the pivot from a randomly chosen location in the input array. Discuss the advantages and disadvantages of such a solution. How does it affect the worst-case and average-case behaviour? [5 marks]
(e) Define the median of an array of n numbers. Then explain clearly how to implement a median() procedure that would use the partition() procedure you described in part (a). (You may, if you wish, illustrate your answer with pseudocode.) Briefly analyse the complexity of this procedure. [5 marks]