GATE / CS ARCHIVE

GATE CSE 1996 / QUESTION 2.15

Quicksort comparisons in opposite orders

Algorithms · Searching, Sorting & Selection · Full GATE CSE 1996 paper

GATE 1996, Q2.15 2 marks · MCQ
Report issue

Searching, Sorting & Selection

Question 2.15, GATE 1996: Compare quicksort comparisons for a list already ascending versus descending when no pivot or partition implementation is specified.
Tap to enlarge
Your answer
Answer & solution

Answer: D in general; C for standard end-pivot worst-case counting (no official key was published)

With the first or last element chosen as pivot on every subarray, either monotone input can split into sizes 0 and n−1. Counting n−1 comparisons per partition gives n(n−1)/2 for both orientations, the usual equality answer C under that model. But the question does not specify pivot selection or partition code. A rule depending on input orientation can select balanced pivots in one case and extreme pivots in the other; even comparison-count conventions vary. Therefore no implementation-independent ordering follows, corresponding to D. The common equal-count result is conditional, not a universal theorem about every quicksort variant.

Original paper, page 5