Data Structures & AlgorithmsVery hardGATE CS · Product-company placement

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

  1. A. 3
  2. B. 15
  3. C. 8
  4. D. 14

Correct answer: D. 14

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic