GATE / CS ARCHIVE

GATE CSE 2015 SET 1 / QUESTION 14

GATE CSE 2015 Set 1 Q14

Algorithms · Searching, Sorting & Selection · Full GATE CSE 2015 Set 1 paper

GATE 2015 Set 1, Q14 1 mark · MCQ
Report issue

Searching, Sorting & Selection

Question 14, GATE 2015: For n≥2, choose the worst-case quicksort recurrence; c is constant. A T(n)=2T(n/2)+cn; B T(n)=T(n−1)+T(1)+cn; C T(n)=2T(n−1)+cn; D T(n)=T(n/2)+cn.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Worst-case pivots repeatedly leave one side with nearly every remaining element. Treat the constant-size side's cost as O(1), yielding T(n)=T(n−1)+Θ(n). Unrolling accumulates n+(n−1)+…+2=Θ(n²). A represents balanced splitting, C duplicates the large subproblem, and D omits one half of a balanced sort. Printed B uses T(1) for constant work.

Solution: The most unbalanced quicksort split leaves one nontrivial subproblem of size n−1 and constant base-case work, plus cn partition work. Hence the listed recurrence T(n)=T(n−1)+T(1)+cn, B, gives Θ(n²).

Original paper, page 7 · Answer key