Skip to main content

GATE CSE 2013Algorithms › Sorting AlgorithmsVerified

GATE CSE 2013 PYQ: The number of elements that can be sorted in Θ ( log ⁡ n ) \Theta(\log n) Θ ( lo g n ) time using heap sort is

The number of elements that can be sorted in Θ(log⁡n)\Theta(\log n) time using heap sort is

  1. A
    Θ(1)\Theta(1)
  2. B
    Θ(log⁡n)\Theta(\sqrt{\log} n)
  3. C
    Θ(log⁡nlog⁡log⁡n)\Theta(\frac{\log n}{\log \log n})
    Correct answer
  4. D
    Θ(log⁡n)\Theta(\log n)

Answer

(C) Θ ( log ⁡ n log ⁡ log ⁡ n ) \Theta(\frac{\log n}{\log \log n}) Θ ( l o g l o g n l o g n ​ )

Approach

The cost of sorting a set of $k$ elements with heap sort is $\Theta(k\log k)$, and this cost grows strictly with $k$. So the question reduces to: for which growth rate of $k$ (as a function of $n$) does $k\log k$ equal $\Theta(\log n)$? Solve $k\log k = \Theta(\log n)$ and check the dominant term.

Heap sort of $k$ elements takes $\Theta(k\log k)$ time, so we need $k$ satisfying $k\log k=\Theta(\log n)$. The choice $k=\Theta\!\left(\frac{\log n}{\log\log n}\right)$ yields $k\log k=\log n\big(1-o(1)\big)=\Theta(\log n)$, while $\log n$ elements would need $\omega(\log n)$ time and $O(\sqrt{\log n})$ elements need only $o(\log n)$ time. Therefore option C is correct.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.