Statement for Linked Answer Questions 76 & 77:
A -ary max heap is like a binary max heap, but instead of children, nodes have children. A -ary heap can be represented by an array as follows: The root is stored in the first location, , nodes in the next level, from left to right, is stored from to . The nodes from the second level of the tree from left to right are stored from location onward. An item can be inserted into a -ary heap containing items by placing in the location and pushing it up the tree to satisfy the heap property.
76. Which one of the following is a valid sequence of elements in an array representing -ary max heap?
View worked solution
Answer: D
In a -ary heap represented by a -indexed array , the root is at index . For any node at index :
- Its children are located at indices: , , and (if they exist).
For an array of size (indices to ), the parent-child relationships are:
- The children of are , , and .
- The children of are and .
For a max-heap, every parent node must be greater than or equal to its children. Thus, the following conditions must hold:
- , , and
- and
Let's evaluate the given options against these conditions:
- Option A:
Here, and . Since , the max-heap property is violated. - Option B:
Here, and its child . Since , the max-heap property is violated. - Option C:
Here, and its child . Since , the max-heap property is violated. - Option D:
Let's verify all conditions:- (True)
- (True)
Free practice · Your answers on this page are not saved.
