Quicksort is run on the two inputs below to sort them in ascending order,…

GATE · 1996 · CS · Question 2 subpartsModified — slightly modified from the official paper; see the solution

Quicksort is run on the two inputs below to sort them in ascending order, using the first element as the pivot:

(i) 1, 2, 3, ..., n
(ii) n, n−1, n−2, ..., 2, 1

Let C1 and C2 be the numbers of element-to-pivot comparisons made for inputs (i) and (ii), respectively. Then:

  1. A.

    C1 < C2

  2. B.

    C1 > C2

  3. C.

    C1 = C2

  4. D.

    We cannot say anything for arbitrary n

Attempted by 191 students.

Sign up free to check your answer

Sign up free

Explore the full course: Algorithms

Loading lesson…