GATE Computer ScienceVery hardGATE CS

In how many different ways can the 10 distinct keys 1, 2, ..., 10 be arranged in the array positions 1 to 10 of a binary max-heap (each node at index i has children 2i and 2i + 1 and is larger than both)?

  1. A. 3780
  2. B. 2520
  3. C. 3360
  4. D. 1260

Correct answer: C. 3360

The root must be 10, and the shape of a 10-node complete tree gives a left subtree of 6 nodes and a right subtree of 3 nodes. H(10) = C(9,6) · H(6) · H(3), and H(6) = C(5,3) · H(3) · H(2) = 10 · 2 · 1 = 20 with H(3) = 2, so H(10) = 84 · 20 · 2 = 3360.

More Algorithms questions

Exams that ask this topic