GATE DA 2026 · Divide & Conquer: Quicksort

MCQ · 1 mark · Problem PROG-SORT-0015

Consider that the quick sort algorithm is used to sort an array of \(n\) distinct randomly ordered elements. In every call, the pivot is chosen as the first element of the current subarray. Let \(T(n)\) denote the expected time to sort the array. Assume that the time to partition is linear in the size of the current subarray.Which of the following recurrence relations correctly represents \(T(n)\) in this scenario?
  1. A
    \(T(n)=T(1)+T(n-1)+O(n)\)
  2. B
    \(T(n)=T\left(\frac{n}{4}\right)+T\left(\frac{3 n}{4}\right)+O(n)\)
  3. C
    \(T(n)=2 T\left(\frac{n}{2}\right)+O(n)\)
  4. D
    \(T(n)=\frac{1}{n} \sum_{k=0}^{n-1}[T(k)+T(n-k-1)]+O(n)\)

Solve it on GATE DA practice →More Searching & Sorting Algorithms problems

Show the worked solutionWith the pivot always chosen as the first element, and the input array being randomly ordered (so the pivot's rank is uniformly random among the \(n\) elements of the current subarray), the pivot ends up at position \(k\) (splitting into a left part of size \(k\) and right part of size \(n-k-1\)) with equal probability \(1/n\) for every \(k=0,1,\ldots,n-1\).Averaging over all these equally likely splits gives the expected-case recurrence:\(T(n)=\dfrac1n\displaystyle\sum_{k=0}^{n-1}\big[T(k)+T(n-k-1)\big]+O(n)\)The other recurrences describe specific worst-case (\(T(n)=T(1)+T(n-1)+O(n)\), when the pivot always lands at an extreme end) or idealized-balanced (\(T(n)=2T(n/2)+O(n)\)) scenarios, not the true randomized average case.Answer: \(T(n)=\frac1n\sum_{k=0}^{n-1}[T(k)+T(n-k-1)]+O(n)\)Click Here for Detail SolutionGateOverflow discussion: https://gateoverflow.in/523210/gate-da-2026-question-5

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com