The number of elements that can be sorted in time using heap sort is
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
- A
- B
- CCorrect answer
- D
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.