511 views
1 votes
1 votes
what if a full binary tree contains both left and right sides as the max heap, then what will be the complexity of making it a proper max heap?

2 Answers

1 votes
1 votes
A full binary tree is a binary tree in which every node has either 0 or 2 children. If a full binary tree contains both left and right sides as max heap, then the time complexity of making it a proper max heap will be O(n) where n is the number of nodes in the tree.

This is because in a full binary tree, each node has two children, and to convert it into a proper max heap, we need to compare the value of each node with its children, swap it if necessary and repeat the process for all the nodes in the tree. Since each node has two children, and the tree is full, we have to repeat this process n times, and hence the time complexity is O(n).
0 votes
0 votes
if a full binary tree contains both left and right sides as the max heap, then the worst-case time complexity of making it a proper max heap is O(log(n)). As the left sub-tree, as well as the right sub-tree, are heaps then I assume they are complete in the worst case.

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
0 answers
2
Dheer asked Nov 22, 2018
338 views
no of max heaps possible with nos given as 1,2,3,4,5?I am getting 8 if you get more please upload solution and do not give direct answers!
0 votes
0 votes
0 answers
3