wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

An array X of n distinct integers is interpreted as a complete binary tree. The index of the first element of the array is 0.

If only the root node does not satisfy the heap property, the algorithm to convert the complete binary tree into a heap has the best asymptotic time complexity of

A
O(n)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
O(n log n)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
O(log n)
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
D
O (n loglog n)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is C O(log n)
Since only root node does not satisfy the heap property, so applying one time heapify will make whole tree as heap. Heapify will take O(log n) i.e. height of heap tree.

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Mathematical Induction
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon