Skip to content
Official PYQ · 2018

GATE CS 2018 Q46 — Binary Heaps

Explain with AI
The number of possible min-heaps containing each value from {1,2,3,4,5,6,7}\{1,2,3,4,5,6,7\} exactly once is _______
View worked solution

Answer: 80

A min-heap containing nn distinct elements is a complete binary tree where the root always contains the minimum element. The remaining n−1n-1 elements are distributed between the left subtree of size LL and the right subtree of size RR (L+R=n−1L + R = n - 1).

The number of ways to construct a min-heap of size nn, denoted as N(n)N(n), is given by the recurrence relation:

N(n)=(n−1L)×N(L)×N(R)N(n) = \binom{n-1}{L} \times N(L) \times N(R)

For n=7n = 7, a complete binary tree has a left subtree of size L=3L = 3 and a right subtree of size R=3R = 3.

  1. Calculate N(3)N(3): For a heap of size 3, the left and right subtrees each have size 1 (L=1,R=1L=1, R=1). N(3)=(21)×N(1)×N(1)=2×1×1=2N(3) = \binom{2}{1} \times N(1) \times N(1) = 2 \times 1 \times 1 = 2
  2. Calculate N(7)N(7): Using N(3)=2N(3) = 2: N(7)=(63)×N(3)×N(3)=20×2×2=80N(7) = \binom{6}{3} \times N(3) \times N(3) = 20 \times 2 \times 2 = 80

Thus, the number of possible min-heaps is 80.

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

Published
Report a correction
Keep exploringMore Binary Heaps questions