GateAI
Binary Heaps

GATE CSE 2024 Set 1 · Q43

MCQ2 marksEasy

Time

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

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) 53

Binary Heaps

In a binary min-heap, every parent node has a value smaller than or equal to the values of its children. Therefore, the maximum element cannot be an internal node (since an internal node must be smaller than its children) and must reside at one of the leaf nodes.

For a complete binary tree/heap with n=105n = 105 elements stored in an array using 1-based indexing:

  • The internal nodes are located at indices 1,2,…,⌊n/2⌋=1,2,…,⌊105/2⌋=521, 2, \dots, \lfloor n/2 \rfloor = 1, 2, \dots, \lfloor 105/2 \rfloor = 52.

  • The leaf nodes are located at indices from ⌊n/2⌋+1\lfloor n/2 \rfloor + 1 to nn, which is from index 5353 to index 105105.

The total number of leaf nodes is:

105−53+1=53105 - 53 + 1 = 53

Since the maximum element can appear at any leaf position, the number of possible values for the index kk is 53.

Hence, (A) is the correct option.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Binary Heaps previous year question is Q43 of the GATE CSE 2024 Set 1 paper. Find more GATE CSE PYQs on Binary Heaps in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Binary Heaps PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Binary Heaps in GATE CSE

Binary Heaps has 15 GATE CSE PYQs across 13 papers from 2011 to 2026. 5 of them are 2-mark MCQs like this one, and GATE CSE 2024 Set 1 has 2.

How GATE tests Binary Heaps

More from GATE CSE 2024 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2024 Set 1 · Q43 · MCQ

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

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.