Which of the following arrays represents a binary max-heap?
2015
Which of the following arrays represents a binary max-heap?
Answer: C. {20, 12, 15, 10, 11, 14, 13} — ConceptA binary max-heap is a complete binary tree in which every parent value is greater than or equal to each child value. In a zero-indexed array, the…
- A.
{20, 12, 15, 14, 10, 7, 8}
- B.
{20, 14, 12, 16, 5, 10, 6}
- C.
{20, 12, 15, 10, 11, 14, 13}
- D.
{20, 12, 15, 10, 11, 16, 13}
- E.
Question not attempted
Attempted by 399 students.
Show answer & explanation
Correct answer: C
Concept
A binary max-heap is a complete binary tree in which every parent value is greater than or equal to each child value.
In a zero-indexed array, the children of index i are at 2i + 1 and 2i + 2 when those indices exist. Conversely, the parent of a node at index j > 0 is at floor((j − 1) / 2), equivalently integer division by 2.
Application
For {20, 12, 15, 14, 10, 7, 8}, index 1 stores 12 and index 3 stores its child 14; because 12 < 14, the parent condition breaks.
For {20, 14, 12, 16, 5, 10, 6}, index 1 stores 14 and index 3 stores its child 16; because 14 < 16, the parent condition breaks.
For {20, 12, 15, 10, 11, 14, 13}, the comparisons are 20 >= 12, 20 >= 15, 12 >= 10, 12 >= 11, 15 >= 14, and 15 >= 13. Every required parent-child comparison holds.
For {20, 12, 15, 10, 11, 16, 13}, index 2 stores 15 and index 5 stores its child 16; because 15 < 16, the parent condition breaks.
The phrase Question not attempted records an omitted response and is not an array representation.
Cross-check
Scanning the internal indices 0, 1, and 2 of {20, 12, 15, 10, 11, 14, 13} finds no child larger than its parent. Therefore, {20, 12, 15, 10, 11, 14, 13} represents the binary max-heap.