Consider a complete binary tree where the left and the right subtrees of the root are max-heaps. The lower bound for the number of operations to convert the tree to a heap is
Consider a complete binary tree where the left and the right subtrees of the root are max-heaps. The lower bound for the number of operations to convert the tree to a heap is Correct Answer Ω (log n)
Consider complete binary tree where left and right subtrees of the root are max-heaps given below
To convert the tree into a heap which is possible by calling MAX-HEAPIFY at root. MAX- HEAPIFY operation takes time as the height of the tree. i.e. if we have n elements in the tree then log(n) is the height of the tree.
Step 1: Swap 10 and 40
Step 2: swap 10 and 25
The above tree is a MAX-HEAP
To convert this into a max heap it takes only 2 swap and 2 comparison which is nothing but the height of the tree. So, log(n) time is required to convert the tree into a heap.