edited by
794 views
3 votes
3 votes

Q). What is the complexity of finding the $50^{th}$ smallest elements in an already constructed binary min-heap?

  1. $\theta(1)$
  2. $\theta(logn)$
  3. $\theta(n)$
  4. $\theta(nlogn)$

solution: 

Exact complexity would be $50logn$ for heapify when we do heap sort iteration $50$ times 

edited by

2 Answers

Best answer
1 votes
1 votes

I think answer for this question should be O(1).

We need to find 50th smallest integer in min heap. Which can be easily done by checking first 250 no in arrays (Checking first 50 levels of heap !) .  It does not depend on size of heap. We can have min heap of size n =  2^250000000000still no of comparisons is fixed. It does not change with no of elements in heap.

selected by
–2 votes
–2 votes
finding smallest element from it is --

we have to apply extract minheap() whose time complexity is O(log n) 50 times i.e 50 log(n) and then O(1) for the 50th smallest number and then inserting the rest 49 element O(log n)*49.

total time complexity=50 log(n)+O(1)+49O(log n)=O(logn)

Related questions

0 votes
0 votes
0 answers
1
Akash Kanase asked Jan 15, 2016
398 views
I got that Statement 3 can be false in case we have function 1/n, then its square become 1/n^2. But I don't think statement 2 is true either. Please prove whether I'm cor...
1 votes
1 votes
1 answer
2
Hradesh patel asked Jan 27, 2017
388 views
plz explain ?? i got O(nlogn)
0 votes
0 votes
1 answer
3
rajan asked Dec 9, 2016
374 views
how to solve these two using matser thorem.1. t(n)=2t(√n)+n2. t(n)=4t(√n)+(logn)^2
1 votes
1 votes
2 answers
4
vijaycs asked Jul 11, 2016
1,892 views
On which of the following recurrence relation Masters theorem can not be applied ?A. T(n)= 2T(n/2) + n (log n).B. T(n) = T(n/2) + 1.C. T(n) = 8T(n/2) + (log n).D. T(n) = ...