Searching, Sorting & Selection
![Question 14, GATE 2014: Quicksort sorts ascending using the first element as pivot. Let t₁ be its comparison count on [1,2,3,4,5] and t₂ the count on [4,1,5,3,2]. Which holds? A: t₁=5. B: t₁<t₂. C: t₁>t₂. D: t₁=t₂. Use the conventional partitioning comparison model.](../../assets/questions/CS-2014-S1-Q24-1.webp)
Answer & solution
Official answer: C
Our answer: C under standard linear partition comparisons
Step through it (2 runs)
1. Method and setup. With the first-element pivot, an already sorted list always selects the smallest remaining value, producing maximally unbalanced recursive subproblems. For the second list, pivot 4 separates three smaller elements from one larger element. Bounding the cost of sorting that three-element side suffices; its exact partition order is unnecessary.
2. Work through the result and its assumptions. Sorted input with first-element pivot repeatedly splits 0 versus n−1, using 4+3+2+1=10 pivot comparisons. The second input first splits 3 versus 1, so its total is 4 plus at most 3 within the three-element side, at most 7. Thus t1>t2, C. This is the usual partition comparison model, not arbitrary redundant implementation tests.