GATE CS 2024 Set 1 | Question 43

MCQ · 2 marks · −0.66

Consider a binary min-heap containing 105 distinct elements. Let \(k\) be the index (in the underlying array) of the maximum element stored in the heap. The number of possible values of \(k\) is

  1. Option A: 53 (correct)
  2. Option B: 52
  3. Option C: 27
  4. Option D: 1

Answer

(A)

Explanation

In a min-heap every parent is smaller than its children, so the maximum element cannot have a child: it must be a leaf. With the 105 elements at indices 1 to 105, the nodes with children are indices 1 to \(\lfloor 105/2 \rfloor = 52\), and the leaves are indices 53 to 105, which is \(105 - 52 = 53\) positions.

Every leaf is possible: put the maximum at any chosen leaf and fill the other positions with the remaining elements in increasing order of index; each parent is still smaller than its children. So \(k\) has 53 possible values (indices 52 to 104 with 0-based indexing, still 53).

Answer: A