159 159 votes The number of elements that can be sorted in $\Theta(\log n)$ time using heap sort is $\Theta(1)$ $\Theta(\sqrt{\log} n)$ $\Theta(\frac{\log n}{\log \log n})$ $\Theta(\log n)$ Algorithms gatecse-2013 algorithms sorting normal heap-sort + – Arjun 43.6k views answer comment Share Follow Print See all 13 Comments 13 13 Comments reply Show 10 previous comments Rish@bh_shukl@ commented Nov 8, 2025 reply Follow flag We can answer this without even lifting pen with option elimination because other options apart from (c) are surely not working if we keep in place of 'n' in nlogn. 1 1 replyShare Abhinav_Jain commented Jan 16 reply Follow flag @goxul thanks ! 0 0 replyShare js__ commented Jan 19 reply Follow flag Kshitij Sharma i too thought the same way ! 0 0 replyShare Please log in or register to add a comment.
Best answer 250 250 votes To sort $k$ elements in a heap, complexity is $\Theta (k \log k)$. Lets assume there are $\frac{\log n}{\log \log n}$ elements in the heap. Complexity $= \Theta\left(\frac{\log n}{\log \log n} \log\left(\frac{\log n}{\log \log n}\right)\right) $ $=\Theta \left( \frac{\log n}{\log \log n} \left({\log \log n}- { \log \log \log n}\right) \right )$ $= \Theta \left ({ \log n} - \frac{ \log n \log \log \log n}{\log \log n} \right )$ $=\Theta (\log n)$ (as shown below) So, (C) is the answer. $\log \log n > \log \log \log n$ $\implies \frac{\log \log \log n}{\log \log n} < 1$ $\implies \frac{ \log n \log \log \log n}{\log \log n} < \log n$ $\implies \Theta \left ( { \log n} - \frac{ \log n \log \log \log n}{\log \log n} \right ) =\Theta (\log n)$ Arjun answered Oct 18, 2014 • edited Nov 14, 2017 by kenzou Arjun comment Share Follow See all 29 Comments 29 29 Comments reply Show 26 previous comments gauravbora commented Nov 24, 2023 reply Follow flag How did you think that there are logn/(loglogn) elements in the heap. There can be log n elements why only logn/loglogn ? 5 5 replyShare Tushar Rana commented Dec 27, 2024 reply Follow flag @gauravbora if it's helpful to find out the valid option then surely solve with that but the only option that will work out is logn/(loglogn) 0 0 replyShare js__ commented Jan 19 reply Follow flag why taking "Lets assume" as correct option then running the task ? 0 0 replyShare Please log in or register to add a comment.
51 51 votes answer = option C amarVashishth answered Oct 20, 2015 1 flag: ✌ Low quality (Hira Thakur “image quality is not clear”) amarVashishth comment Share Follow See all 3 Comments 3 3 Comments reply Rajesh Pradhan commented Nov 10, 2016 reply Follow flag WooW..Nice Solution. 1 1 replyShare panipuri commented Aug 10, 2025 reply Follow flag above answer upscaledHeap sort sorts $k$ elements in time $\Theta(k \log k)$. Let's try this with the given choices of $k$:1. $k = \Theta(1)$ $$\Theta(k \log k) = \Theta(1 \log 1) = \Theta(1)$$ wrong (too fast).2. $k = \Theta(\sqrt{\log n})$ $$\Theta(k \log k) = \Theta\left(\sqrt{\log n} \log\left(\sqrt{\log n}\right)\right)$$ $$= \Theta\left(\sqrt{\log n} \cdot \frac{1}{2} \log \log n\right)$$ wrong (too fast).3. $k = \Theta\left(\frac{\log n}{\log \log n}\right)$ $$\Theta(k \log k) = \Theta\left(\frac{\log n}{\log \log n} \cdot \log \frac{\log n}{\log \log n}\right)$$ $$= \Theta\left(\frac{\log n}{\log \log n} \cdot (\log \log n - \log \log \log n)\right)$$ $$= \Theta(\log n - \log \log n) = \Theta(\log n)$$ right!4. $k = \Theta(\log n)$ $$\Theta(k \log k) = \Theta(\log n \log \log n)$$ wrong (too slow). 9 9 replyShare TanayH commented Dec 22, 2025 reply Follow flag Image for ants! 6 6 replyShare Please log in or register to add a comment.
16 16 votes C. heap sort of x element takes $x \log x$ time. So, if $x = \frac{\log n}{\log \log n}$ time required is coming out to be : $\log n - \frac{\log n * \log \log \log n}{\log \log n}$ Second term vanishes when n is very large. dd answered Aug 29, 2016 dd comment Share Follow See all 4 Comments 4 4 Comments reply rahul sharma 5 commented Oct 1, 2017 reply Follow flag How will second term vanishes. logloglogn / loglogn will always be less than 1 but for large n it will not be 0 and it will always give some fraction.so overall it reduces logn -y*logn, where y is the fraction from above(<1). Can you please tell how will second term vanish? 0 0 replyShare Rupendra Choudhary commented Jan 13, 2018 reply Follow flag $\lim_{x->0}logn*(1-x)=logn$ 0 0 replyShare Abhineet Singh commented Nov 22, 2020 reply Follow flag i dont think 2nd term will vanish, 2nd term is greater than 1 because of logn in the numerator. Can you explain how it will vanish... 0 0 replyShare Akash 1234Upadhyay commented Jul 8, 2021 reply Follow flag we can think $log$$log$$log$n/$log$$log$n as $log$x/x where x is $log$$log$n, when x approach infinite then $log$x/x will become 0 so answer is θ($log$n) 0 0 replyShare Please log in or register to add a comment.
4 4 votes answer is C . Niraj Singh 2 answered Jun 21, 2017 Niraj Singh 2 comment Share Follow 0 reply Please log in or register to add a comment.
3 3 votes @ Arjun Sir . I have tried to do like this. Please point out the error if any Worst case time complexity of quick sort =O(nlogn) O(nlog n) time - n elements Taking 'log' on both sides log (nlog n) = log n -> log n + log log n = logn -> O(log n) = log n - log log n O(log n) = log n /log log n elements Hence option C. Please check it. sutanay3 answered Jul 31, 2018 sutanay3 comment Share Follow See all 3 Comments 3 3 Comments reply amitqy commented Oct 21, 2018 reply Follow flag In heap sort n elements can be sorted in nlogn time in worst case. in 1 unit of time = n/nlogn elements can be sorted. in log n time = (n/nlogn)*logn = theta(1) please tell me what blunder am I making.I want to know where I am wrong. 1 1 replyShare Markzuck commented Jan 15, 2019 reply Follow flag @amitqyWhy is this logic incorrect? We solve most of the order based using this na? 0 0 replyShare amitqy commented Jan 15, 2019 reply Follow flag What n stands for is not mentioned in the question,I assumed n as total no. of element,thats where I went wrong. 1 1 replyShare Please log in or register to add a comment.
2 2 votes Heap sort requires $\Theta(k \log k)$ time to sort $k$ elements.We seek the largest $k$ such that $$\Theta(k \log k) = \Theta(\log n).$$Thus, we solve $k \log k = \Theta(\log n)$ for $k$.Assume $k = \dfrac{\log n}{\log \log n}$. Then:$$\log k = \log\!\left(\frac{\log n}{\log \log n}\right) = \log \log n - \log \log \log n = \Theta(\log \log n).$$Therefore,$$k \log k = \frac{\log n}{\log \log n} \cdot \Theta(\log \log n) = \Theta(\log n).$$Hence, sorting $k = \Theta\!\left(\dfrac{\log n}{\log \log n}\right)$ elements takes $\Theta(\log n)$ time.Checking other options: If $k = \Theta(\log n)$, then $k \log k = \Theta(\log n \cdot \log \log n) \gg \Theta(\log n)$. If $k = \Theta(1)$, then $k \log k = \Theta(1) \ll \Theta(\log n)$. If $k = \Theta(\sqrt{\log n})$, then $k \log k = \Theta(\sqrt{\log n} \cdot \log \log n) = o(\log n)$.Thus, only option C satisfies the required condition.Final Answer: $$\boxed{\text{C. }\Theta\left(\dfrac{\log n}{\log \log n}\right)}$$ parity answered Oct 17, 2025 parity comment Share Follow 0 reply Please log in or register to add a comment.