Question

Which one of the following is the recurrence equation for the worst case time complexity of the Quicksort algorithm for sorting nn (n≥2n \ge 2) numbers? In the recurrence equations given in the options below, cc is a constant.

Choose one option
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 nn elements is partitioned using a pivot. Partitioning takes linear time, cncn.

In the worst case (such as when the array is already sorted and the extreme element is chosen as pivot):

  • One partition contains n−1n - 1 elements.
  • The other partition contains 00 (or 11) element.

Thus, the recurrence relation describing this behavior is:

T(n)=T(n−1)+T(1)+cn.T(n) = T(n-1) + T(1) + cn.

This matches option B.

Final answer

B

Common trap

Confusing worst-case Quicksort with best/average case T(n)=2T(n/2)+cnT(n) = 2T(n/2) + cn (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.