GATE / CS ARCHIVE

GATE CSE 2014 SET 3 / QUESTION 14

GATE CSE 2014 Set 3 Q14

Algorithms · Searching, Sorting & Selection · Full GATE CSE 2014 Set 3 paper

GATE 2014 Set 3, Q14 1 mark · MCQ
Report issue

Searching, Sorting & Selection

Question 14, GATE 2014: Quicksort on n elements always selects the element at the central array index as pivot. What is the tightest listed worst-case upper bound? A O(n²); B O(n log n); C Θ(n log n); D O(n³).
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Step 1: A central position in an array is not necessarily the median value. An adversarial ordering can place the smallest or largest current value at each selected pivot position. Step 2: Partitioning then leaves subproblems of sizes 0 and n−1 while doing Θ(n) work. The recurrence is T(n)=T(n−1)+Θ(n). Step 3: Summing the partition costs gives Θ(n+(n−1)+…+1)=Θ(n²). Therefore A is the tightest offered upper bound; O(n³) is true but weaker.

Original paper, page 56 · Answer key