Let be a binary min-heap consisting of elements implemented as an array. What is the worst case time complexity of an optimal algorithm to find the maximum element in ?
View worked solution
Answer: C
In a binary min-heap of size , the elements satisfy the min-heap property where the key of each node is less than or equal to the keys of its children. Consequently:
- The minimum element is always located at the root node (index or in the array representation).
- The maximum element cannot have any children, meaning it must be located at one of the leaf nodes.
For a complete binary tree with elements, the leaf nodes are located in the second half of the array, specifically from index to (using 0-based indexing). The number of leaf nodes is .
Since there is no relative ordering or heap property maintained among the leaf nodes themselves, finding the maximum element requires a linear scan over all the leaf nodes.
The time complexity to find the maximum among the unsorted leaf elements is:
Therefore, the worst-case time complexity of an optimal algorithm to find the maximum element in a binary min-heap is .
Free practice · Your answers on this page are not saved.
