Let \(P\) be a quicksort program to sort numbers in ascending order. Let…

PYQ GATE 1987Modified — slightly modified from the official paper; see the solution

Let PP be a quicksort program to sort numbers in ascending order. Let t1t_{1} and t2t_{2} be the time taken by the program for the inputs [1 2 3 4]\left[1 \ 2 \ 3 \ 4\right] and [5 4 3 2 1]\left[5 \ 4 \ 3 \ 2 \ 1\right], respectively. Which of the following holds? Assume each partition chooses the first element as pivot, compares it once with each other element in that partition, and that time is measured by this comparison count.

  1. A.

    t1=t2t_{1} = t_{2}

  2. B.

    t1>t2t_{1} > t_{2}

  3. C.

    t1<t2t_{1} < t_{2}

  4. D.

    t1=t2+5log⁡5t_{1}=t_{2}+5 \log 5

Attempted by 84 students.

Sign up free to check your answer

Sign up free

Explore the full course: Algorithms

Loading lesson…