Question
Which one of the following is the recurrence equation for the worst case time complexity of the Quicksort algorithm for sorting () numbers? In the recurrence equations given in the options below, is a constant.
Official answer and solution
- Official answer
- B
- From
- Official GATE 2015 answer key
Solution
Formulate the recurrence relation for Quicksort when the partition is maximally unbalanced at each recursive step.
In Quicksort, an array of elements is partitioned using a pivot. Partitioning takes linear time, .
In the worst case (such as when the array is already sorted and the extreme element is chosen as pivot):
- One partition contains elements.
- The other partition contains (or ) element.
Thus, the recurrence relation describing this behavior is:
This matches option B.
B
Confusing worst-case Quicksort with best/average case (option A).
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2015 Computer Science and Information Technology (CS) Session 1
- Question
- 12 of 65, printed as CS Q.2
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.