412 views
1 votes
1 votes

Q Consider a complete Binary Tree ‘T’ with key of root node be ‘P’. It is given that the left and right subtree of ‘P’ satisfies min-heap property. What is the time taken to convert the given tree ‘T’ to a max heap ?

1.O(log n)

2.O(n)

3. O(n log n)

4.Ο(n2)

1 Answer

3 votes
3 votes

The answer should be O(n). Since there is no better way to convert a min heap to max heap (or vice-versa) than to reconstruct the heap in O(n). Given additional features like left and right subtrees being min heap won't help either.

Related questions

0 votes
0 votes
0 answers
1
Na462 asked Jan 16, 2019
388 views
Consider a binary tree for every node | P - Q | <= 2. P represents number of nodes in left subtree of S and Q represents number of nodes in right subtree of S for h 0. T...
0 votes
0 votes
0 answers
2
0 votes
0 votes
0 answers
3
Soumya29 asked Oct 22, 2018
306 views
I know the answer. But is there any general FORMULA for it?If yes, please provide the complete derivation of it. In the solution, they used $\rightarrow 2^{h-1}+1.$ I tri...
0 votes
0 votes
0 answers
4
Na462 asked Oct 20, 2018
621 views
Consider 4 labeled 1,2,3,4. The number of distinct binary tree possible such that whose inorder traversal is 1,2,3,4 are ........