View worked solution
Answer: 511
In a binary min-heap, the parent node is always smaller than or equal to its children. Consequently, the maximum element cannot be an internal node (as any internal node is smaller than its descendants). Thus, the maximum element must reside in one of the leaf nodes.
For a binary heap represented as an array of size (using 1-based indexing):
- The internal nodes are located at indices to .
- The leaf nodes are located at indices from to .
Given :
Thus, the leaf nodes are located at indices from to .
The total number of leaf nodes () is:
Since there is no ordering guarantee among the leaf nodes, finding the maximum element among these elements requires finding the maximum of an unsorted list of size .
The minimum number of comparisons required to find the maximum of unsorted elements is:
Free practice · Your answers on this page are not saved.
