in Algorithms retagged by
28,040 views
113 votes
113 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)$
in Algorithms retagged by
by
28.0k views

4 Comments

If you can solve this way then why not divide both side with n in the first step only.
Then you you will get   

1 elements⟶Θ(log(n)) time is required.

But this is not the answer.
3
3
k log k not k logn ,i think
0
0

@!KARAN this is called first checking the solution and then producing the answer.

I guess we cant do it that way .

2
2

8 Answers

185 votes
185 votes
Best answer

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
by

4 Comments

Is this question solvable without the options?
1
1

i think if instead of O(logn) if they had given some constant time then may be!

0
0
How did you think that  there are log⁡n/(log⁡log⁡n) elements in the heap.
There can be log n elements why only logn/loglogn ?
0
0
37 votes
37 votes

answer = option C

1 comment

WooW..Nice Solution.
1
1
12 votes
12 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.
by

4 Comments

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
$\lim_{x->0}logn*(1-x)=logn$
0
0

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

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
4 votes
4 votes

answer is C .