GATE / CS ARCHIVE

GATE CSE 1992 / QUESTION 3(iv)

A worst input for last-pivot quicksort

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

GATE 1992, Q3(iv) Descriptive
Report issue

Searching, Sorting & Selection

Question 3(iv), GATE 1992: Quicksort always uses the final element as pivot. Give a worst-case permutation of distinct keys 1, …, n.
Question 3(iv), GATE 1992: Quicksort always uses the final element as pivot. Give a worst-case permutation of distinct keys 1, …, n.
Tap to enlarge
Answer & solution

Answer: Ascending order 1, 2, …, n under the standard partition implementation (no official key was published)

On ascending input, the last pivot is the maximum. Partitioning places every other element on one side, creating subproblem sizes n−1 and 0. If the standard partition preserves the ascending order of that remaining region, the same imbalance repeats. Comparisons sum to (n−1)+(n−2)+…+1=n(n−1)/2, which is Θ(n²). Reverse order is another common worst-case input. The statement concerns ordinary end-pivot partitioning, not a modified algorithm that deliberately rearranges or selects pivots differently after inspecting the data.

Original paper, page 5