GATE CS 2024 Set 1 — Question 43

MCQ+2 / -0.67MediumMin-Heap & Max-HeapHeapsProgramming & Data Structures

Programming & Data Structures → Heaps → Min-Heap & Max-Heap

Last updated

Question

Consider a binary min-heap containing 105 distinct elements. Let kk be the index (in the underlying array) of the maximum element stored in the heap. The number of possible values of kk is
A.
53
B.
52
C.
27
D.
1

Correct answer

(A) 53

Solution

In a min-heap, the property is that every parent node is smaller than or equal to its children. Consequently, the smallest element is at the root, and the largest element must be one of the leaf nodes. It cannot be an internal node because an internal node must be smaller than its children.
In a binary heap with nn distinct elements, the structure is a complete binary tree. The number of leaf nodes in a complete binary tree with nn nodes is given by n/2\lceil n/2 \rceil.
Given n=105n = 105:
Number of leaves = 105/2=52.5=53\lceil 105/2 \rceil = \lceil 52.5 \rceil = 53.
The maximum element can be located at any of these leaf positions. Therefore, there are 53 possible values for the index kk.

More questions on Heaps

Practice GATE CS PYQs with adaptive difficulty

Timed practice, skill tracking, and AI explanations — free to start.

Start practicing free