Skip to content
Official PYQ · 2009

GATE CS 2009 Q59 — Binary Heaps

Explain with AI

Consider a binary max-heap implemented using an array.
Which one of the following array represents a binary max-heap?

Choose one option
View worked solution

Answer: C

In an array-based representation of a binary heap (using 1-based indexing), a node at index ii has its left child at index 2i2i and its right child at index 2i+12i + 1.

For a max-heap, the value of a parent node must be greater than or equal to the values of its children: A[i]≥A[2i]A[i] \ge A[2i] and A[i]≥A[2i+1]A[i] \ge A[2i+1].

Let us evaluate the options:

  • Option A: {25,12,16,13,10,8,14}\{25, 12, 16, 13, 10, 8, 14\}
    At index 22, the parent is 1212. Its left child at index 44 is 1313. Since 12<1312 < 13, this violates the max-heap property.
  • Option B: {25,14,13,16,10,8,12}\{25, 14, 13, 16, 10, 8, 12\}
    At index 22, the parent is 1414. Its left child at index 44 is 1616. Since 14<1614 < 16, this violates the max-heap property.
  • Option C: {25,14,16,13,10,8,12}\{25, 14, 16, 13, 10, 8, 12\}
    Let's check all parent-child relations:
    • Index 11 (2525) ≥\ge Index 22 (1414) and Index 33 (1616)   (True)
    • Index 22 (1414) ≥\ge Index 44 (1313) and Index 55 (1010)   (True)
    • Index 33 (1616) ≥\ge Index 66 (88) and Index 77 (1212)   (True)
    All conditions are satisfied. Thus, this represents a valid max-heap.
  • Option D: {25,14,12,13,10,8,16}\{25, 14, 12, 13, 10, 8, 16\}
    At index 33, the parent is 1212. Its right child at index 77 is 1616. Since 12<1612 < 16, this violates the max-heap property.

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

Published
Report a correction
Keep exploringMore Binary Heaps questions