Docsity

Data structure and algorithm review questions, Exercises of Computer Science

Toggle sidebar
bg1
2008 Paper 11 Question 7
Data Structures and Algorithms
Quicksort can be described as a recursive in-place sorting algorithm that performs
apartition() 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 nnumbers. 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]
1

Partial preview of the text

Download Data structure and algorithm review questions and more Exercises Computer Science in PDF only on Docsity!

2008 Paper 11 Question 7

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]