Skip to content
Official PYQ · 2006

GATE CS 2006 Q76 — Binary Heaps

Explain with AI

Statement for Linked Answer Questions 76 & 77:

A 33-ary max heap is like a binary max heap, but instead of 22 children, nodes have 33 children. A 33-ary heap can be represented by an array as follows: The root is stored in the first location, a[0]a[0], nodes in the next level, from left to right, is stored from a[1]a[1] to a[3]a[3]. The nodes from the second level of the tree from left to right are stored from a[4]a[4] location onward. An item xx can be inserted into a 33-ary heap containing nn items by placing xx in the location a[n]a[n] 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 33-ary max heap?

Choose one option
View worked solution

Answer: D

In a 33-ary heap represented by a 00-indexed array aa, the root is at index 00. For any node at index ii:

  • Its children are located at indices: 3i+13i + 1, 3i+23i + 2, and 3i+33i + 3 (if they exist).

For an array of size 66 (indices 00 to 55), the parent-child relationships are:

  • The children of a[0]a[0] are a[1]a[1], a[2]a[2], and a[3]a[3].
  • The children of a[1]a[1] are a[4]a[4] and a[5]a[5].

For a max-heap, every parent node must be greater than or equal to its children. Thus, the following conditions must hold:

  1. a[0]≥a[1]a[0] \ge a[1], a[0]≥a[2]a[0] \ge a[2], and a[0]≥a[3]a[0] \ge a[3]
  2. a[1]≥a[4]a[1] \ge a[4] and a[1]≥a[5]a[1] \ge a[5]

Let's evaluate the given options against these conditions:

  • Option A: [1,3,5,6,8,9][1, 3, 5, 6, 8, 9]
    Here, a[0]=1a[0] = 1 and a[1]=3a[1] = 3. Since 1<31 < 3, the max-heap property is violated.
  • Option B: [9,6,3,1,8,5][9, 6, 3, 1, 8, 5]
    Here, a[1]=6a[1] = 6 and its child a[4]=8a[4] = 8. Since 6<86 < 8, the max-heap property is violated.
  • Option C: [9,3,6,8,5,1][9, 3, 6, 8, 5, 1]
    Here, a[1]=3a[1] = 3 and its child a[4]=5a[4] = 5. Since 3<53 < 5, the max-heap property is violated.
  • Option D: [9,5,6,8,3,1][9, 5, 6, 8, 3, 1]
    Let's verify all conditions:
    • a[0]=9≥max⁡(a[1],a[2],a[3])=max⁡(5,6,8)=8a[0] = 9 \ge \max(a[1], a[2], a[3]) = \max(5, 6, 8) = 8 (True)
    • a[1]=5≥max⁡(a[4],a[5])=max⁡(3,1)=3a[1] = 5 \ge \max(a[4], a[5]) = \max(3, 1) = 3 (True)
    All conditions are satisfied.

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

Published
Report a correction
Keep exploringMore Binary Heaps questions