retagged by
43,610 views
159 159 votes

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

  1. $\Theta(1)$
  2. $\Theta(\sqrt{\log} n)$
  3. $\Theta(\frac{\log n}{\log \log n})$
  4. $\Theta(\log n)$

11 Answers

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)$

edited by
51 51 votes

answer = option C

1 flag:
✌ Low quality (Hira Thakur “image quality is not clear”)
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.
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.
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)}
$$

Answer:
Position:
Show:

Related questions

55 55 votes
3 answers 3 answers
18.0k
18.0k views
Arjun asked Sep 23, 2014
18,026 views
Which one of the following is the tightest upper bound that represents the number of swaps required to sort $n$ numbers using selection sort?$O(\log n$)$O(n$)$O(n \log n$...
2 2 votes
2 answers 2 answers
2.6k
2.6k views
Bikram asked Nov 26, 2016
2,626 views
Meena is working in an IT company as HR manager. She has a large list of potential candidates to be recruited which are all sorted by their names. But she found that due ...
3 3 votes
3 3 answers
1.6k
1.6k views
admin asked Sep 28, 2024
1,555 views
Worst case time complexity of heap sort for $n$ elements?$O(n\log n)$$O(\log n)$$O({n}^2)$$O(n)$
28 28 votes
3 3 answers
19.2k
19.2k views
Arjun asked Feb 16, 2024
19,234 views
​​​​​An array $[82,101,90,11,111,75,33,131,44,93]$ is heapified. Which one of the following options represents the first three elements in the heapified array?$82,90,101$...