Skip to content
Official PYQ · 2011

GATE CS 2011 Q23 — Binary Heaps

Explain with AI

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
View worked solution

Answer: B

A max-heap must satisfy two essential properties:

  1. Shape Property (Complete Binary Tree): All levels of the tree must be completely filled, except possibly the last level, which must be filled from left to right.
  2. Max-Heap Property: For every node ii (except the root), the value of the parent of ii must be greater than or equal to the value of ii (parent(i)≥node(i)\text{parent}(i) \ge \text{node}(i)).

Let us evaluate each option based on these properties:

  • Option A: Violates the max-heap property because the root node with value 1010 has a right child with value 1212 (since 12>1012 > 10, the parent is smaller than its child).
  • Option B:

    The tree structure is:

              10
             /  \
            8    5
           / \  /
          7   6 4
        
    • It is a complete binary tree because all levels are filled from left to right.
    • It satisfies the max-heap property at every node:
      • 10≥810 \ge 8 and 10≥510 \ge 5
      • 8≥78 \ge 7 and 8≥68 \ge 6
      • 5≥45 \ge 4
    Thus, this is a valid max-heap.
  • Option C: Violates the complete binary tree property because the node 55 has a right child 44 but no left child. The last level is not filled from left to right.
  • Option D: Violates the max-heap property because the node 55 has a right child 1111, and 11>511 > 5.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Binary Heaps questions