GateAI
Binary Heaps

GATE CSE 2020 · Q47

NAT2 marksMedium

Time

Consider the array representation of a binary min-heap containing 1023 elements. The minimum number of comparisons required to find the maximum in the heap is _________.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 511

Binary Heaps

In a binary min-heap, the minimum element is stored at the root, and for any node, its value is less than or equal to the values of its children.

Consequently, the maximum element must be located at one of the leaf nodes.

### 1. Count the number of leaf nodes: For a complete binary tree with N=1023N = 1023 elements:

Number of internal nodes=⌊N/2⌋=⌊1023/2⌋=511\text{Number of internal nodes} = \lfloor N / 2 \rfloor = \lfloor 1023 / 2 \rfloor = 511
Number of leaf nodes=N−511=1023−511=512\text{Number of leaf nodes} = N - 511 = 1023 - 511 = 512

(The leaves occupy indices ⌈N/2⌉=512\lceil N/2 \rceil = 512 to 10231023).

### 2. Finding the maximum among the leaves: To find the maximum element among kk candidates, we need to perform pairwise comparisons:

Minimum comparisons=k−1\text{Minimum comparisons} = k - 1

For k=512k = 512 leaves:

Minimum comparisons=512−1=511\text{Minimum comparisons} = 512 - 1 = 511

Thus, the answer is 511.

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 Q47 of the GATE CSE 2020 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. 2 of them are 2-mark NAT questions like this one, and it is the only one in GATE CSE 2020.

How GATE tests Binary Heaps

More from GATE CSE 2020

Share this solution

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

GateAI solution cardGATE CSE 2020 · Q47 · NAT

Consider the array representation of a binary min-heap containing 1023 elements. The minimum number of comparisons required to find the maximum in the heap 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.