Similar questions 3 more →
Heaps & Priority Queues

Answer & solution
Official answer: 511
Worked explanation
In a one-based heap array, node i has children 2i and 2i+1 when present. Therefore internal nodes are 1…floor(1023/2)=511 and leaves are 512…1023, totaling 512. Every internal value is at most a descendant leaf value by repeatedly applying the min-heap property, so a maximum exists among leaves. There is no ordering constraint between distinct leaves. In the worst case each of 511 nonwinning leaf candidates must lose a comparison to eliminate it; one comparison can eliminate at most one candidate. A scan maintaining the largest leaf seen uses exactly 511 comparisons and attains that bound.
Derivation and answer
The1023-node complete binary min-heap has 512 leaves, at array positions 512–1023 under one-based indexing. A maximum can be chosen among the leaves; their relative values are otherwise unconstrained by the heap property. Finding the maximum of 512 candidates requires 511 comparisons in the worst case, achievable by a linear scan. This is the optimal guaranteed comparison count, not a claim about every favorable tied instance.