Data Structures & AlgorithmsVery hardGATE CS · Product-company placement

A min-heap holds 63 distinct keys in a 0-indexed array (a full tree with 6 levels). At how many different indices can the 5th-smallest key possibly be?

  1. A. 4
  2. B. 30
  3. C. 31
  4. D. 16

Correct answer: B. 30

The 5th-smallest key has at most 4 smaller keys, so all its ancestors come from them: it sits at depth 1 to 4, and every such slot is reachable. That is 2 + 4 + … + 2^4 = 30 positions (never the root).

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic