Consider a binary max-heap implemented using an array. Which among the following arrays represents a binary max-heap ?
Tripura Public Service Commission - 2025,
Answer: A
The max-heap is 25,12,16,8,10,13,14.
In an array heap the children of position i are at 2i and 2i + 1. Check each parent: 25 is above 12 and 16; 12 is above 8 and 10; 16 is above 13 and 14. Every parent is at least as large as its children.
The others fail: in 25,12,16,13,10,8,14 the node 12 has child 13; in 25,14,12,13,10,8,16 the node 12 has child 16; and in 25,14,12,13,10,16,8 the node 12 again has child 16.
Please log in or register to report this question.