Question

A max-heap is a heap where the value of each parent is greater than or equal to the value of its children. Which of the following is a max-heap?

Choose one option
Official answer and solution
Official answer
B
From
Official GATE 2011 answer key

Solution

Examine both the structural complete binary tree property and the max-heap ordering property for each tree.

  1. By definition, a binary max-heap is an almost complete binary tree satisfying the max-heap property: for every node ii other than the root, parent(i)≥i\text{parent}(i) \ge i.
  1. In Tree C: Node 5 has child 8, but 5<85 < 8, violating the max-heap property.
  1. In Tree D: Root 5 has child 8, but 5<85 < 8, violating the max-heap property.
  1. In Tree A: The tree structure is not a complete binary tree because node 8 is missing its right child while node 6 has children extending to a lower level.
  1. In Tree B: Root 10 has children 8 and 6 (10≥8,610 \ge 8, 6). Node 8 has children 4 and 5 (8≥4,58 \ge 4, 5). Node 6 has children 1 and 2 (6≥1,26 \ge 1, 2). The tree is a complete binary tree with all levels filled except possibly the last level filled from left to right. Hence, Tree B is a valid max-heap.
Final answer

B

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2011 Computer Science and Information Technology (CS)
Question
23 of 65, printed as CS Q.23
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.