Consider a binary max-heap implemented using an array.
Which one of the following array represents a binary max-heap?
View worked solution
Answer: C
In an array-based representation of a binary heap (using 1-based indexing), a node at index has its left child at index and its right child at index .
For a max-heap, the value of a parent node must be greater than or equal to the values of its children: and .
Let us evaluate the options:
- Option A:
At index , the parent is . Its left child at index is . Since , this violates the max-heap property. - Option B:
At index , the parent is . Its left child at index is . Since , this violates the max-heap property. - Option C:
Let's check all parent-child relations:- Index () Index () and Index () (True)
- Index () Index () and Index () (True)
- Index () Index () and Index () (True)
- Option D:
At index , the parent is . Its right child at index is . Since , this violates the max-heap property.
Free practice · Your answers on this page are not saved.
