In a binary max heap containing numbers, the smallest element can be found in time
View worked solution
Answer: A
In a binary max-heap of size , the properties of the heap structure dictate where elements are located:
- The largest element is always at the root (index in an array representation).
- The smallest element must be one of the leaf nodes, as any path from the root to a leaf is non-increasing.
In a complete binary tree with elements, the leaf nodes are located at indices from to . The number of leaf nodes is , which is .
Since the leaf nodes are not maintained in any sorted order relative to each other, we must perform a linear search across all the leaf nodes to find the minimum element. This search requires checking elements, which takes time in the worst case.
Therefore, the smallest element can be found in time.
Free practice · Your answers on this page are not saved.
