search
Log In
0 votes
533 views
Consider a binary tree, where left and right subtreealready heapified. But we havenot done heapificationfor root yet. Then what is time complexity to convert it in a full heap tree?

$A)O(\log n)$ or $o(n)$   $B)\Omega (\log n)$ or $\omega(n)$  $C)\Theta (\log n)$ or $\theta (n)$  $D)\text{None of these}$
in DS 533 views
0
I think it should be A) because it cant take more than logn time in any case but it can be less than that, even O(1).
0
i hope, option A is more accurate... why?

we have log n levels in the heap, it is sure...

it is saying that already its left sub-tree and right sub-tree is heapified

therefore remaining is root only, on heapifying the value( initially at the root node), may go atmost the last level (log n level) ------> it is not always happens ===> Θ ( log n ) wrong

and it can not be more than log n ===> Ω( log n) cancelled,  the remaining option is A

with in the A also my choice is O( log n ) due to some time it is equal to ( log n ).
0

@Shaik Masthan,

on heapifying the value( initially at the root node), may go atmost the last level (log n level) ------> it is not always happens ===> Θ ( log n ) wrong 

I might be wrong, please correct me

Here, Big Oh means everything equal to or below the c.g(n) is possible but not above and even in heapify, the complexity can be below or equal to logn

Whereas, Omega means it can be logn or anything more than that.

Where did I go wrong?

0

@Vikas Verma, yes you are right... my analysis is correct but i just mis-used the terms... i will update my comment..

0
@Vikas

do u mean Omega n wrong?

because it cannot go more than log n? Plz explain more
0
yes Omega(n) is wrong...
0

@Shaik

where is switching time of last element to root?

is it O(1)?because

Deleting in a heap, why does this implementation switch the values of the last element, not just replace it?

 

0
mam, i didn't get what do you mean exactly?

did you mean time for SWAPS?
0
yes ,swaps last predecessor to the deleted place
0
@srestha,

Yes it can't be omega logn because it would mean that the time complexity can be anywhere between logn and n^n. Whereas O logn mean it can be anywhere between O(1) and logn.

If we account for the swap time, it will be O(1) + O(logn) and still come down to O(logn)
0
if you are using array for implementing heap, just replaces the values ===>O(1)

if you are using linked list  for implementing heap, just update the pointers ===>O(1)
0

@Vikas @Shaik

actually in gate question only I got 2 type of answer

here it is omega(n) and in another place O(n). that is why I got confused

https://gateoverflow.in/8091/gate2015-2-17

So, according to u this question have some error?

0
As we know under any circumstances the complexity can't go above logn hence maximum TC is logn
Now coming our question, option A says either it will be equal or less OR strictly less than logn
Which sounds great because in worst case input it will be logn and for the rest of the cases it will be less than that.
Coming to the question srestha mentioned in the above comment, none other option satisfies the answer except omega log n because only that says EQUAL to or more than logn.
So in the worst case input, the best we would be able to do is logn. Anything other than that would not be the best possible solution.
0

@srestha,

in this question https://gateoverflow.in/8091/gate2015-2-17, they are interested in lower bound

what is lower bound for that, it is required only 1 comparission operation, i mean root is already satisfied

therefore your complexity = constant

T(n) = Ώ( log n)

 

But in your question, generally we do for upper bound = log n in our case,

T(n) = O ( log n)

0

I think that the answer should be A, as per the question both the left sub tree and the right sub tree are already heapified. Which means that the root node is the only one on which we have to perform the heapify operation.

1) The worst case will be when it can traverse upto the leaf node, i.e in worst case it will take O(logn). 
2) The best case will be when the root is already at the best place that means its position is not going to change i.e will take O(1).

So, finally the time taken would be between O(logn) to O(1).

Please correct me if i am wrong.

0

what is lower bound for that, it is required only 1 comparission operation, i mean root is already satisfied

then theta should be better

and lower bound and upper bound, does it really do any change in complexity

I think it will be better for theta i.e. avg case algo 

and lower bound and upper bound almost it matter nothing to find TC

https://gateoverflow.in/1026/gate2004-29?show=173010

0
Yes I also think option a would be correct  one time complexity  will be less than logn or equal to logn here
0

how here  f1(n) slower than f2(n)?

plz chk

https://gateoverflow.in/177712/running-time

0
srestha is it A na ? what is conclusion

Please log in or register to answer this question.

Related questions

1 vote
1 answer
1
542 views
What is the time complexity to find the Kth largest element in a Min-Heap? Or equivalently, What is the time complexity to find Kth smallest element in Max-Heap?
asked Dec 1, 2018 in Algorithms gmrishikumar 542 views
6 votes
3 answers
2
1.9k views
In a min-heap with n elements 1). The 7th smallest element can be found in time, if duplicates are allowed ? 2). The 7th distinct smallest element can be found in time, If duplicates are allowed ?
asked Sep 4, 2016 in Algorithms Kapil 1.9k views
0 votes
0 answers
3
713 views
This question is in CLRS,if we have a max heap it is always in sorted order(descending) order.And by extension if we have min heap the array is sorted in ascending order.Is this true? I have a counter example for 100,50,20,1,3,10,5,this satisfied max- ... it as an array is it an heapified representation or not? If we heapify after deletion and store max deleted element then we get sorted array.
asked Nov 15, 2018 in DS sripo 713 views
0 votes
0 answers
4
670 views
What is the number of comparisons required to extract 45th element of the min heap?
asked Sep 10, 2018 in Algorithms bts1jimin 670 views
...