Data Structures & AlgorithmsHardProduct-company MCQ pattern

How many different max-heaps (as arrays) can be formed from 5 distinct keys?

  1. A. 8
  2. B. 16
  3. C. 6
  4. D. 120

Correct answer: A. 8

The largest key is the root. The left subtree has 3 nodes (indices 1, 3, 4), the right has 1. Choose which 3 of the remaining 4 keys go left: C(4, 3) = 4; the left sub-heap's root is forced and its 2 children can be ordered 2 ways: 4 × 2 = 8 (brute force over 120 arrays agrees).

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic