GATE Computer ScienceHardGATE CS (PYQ pattern)

An AVL tree of height 6 (a single node has height 0) has the minimum possible number of nodes, and its keys are 1, 2, ..., n for that minimum n. At the root, the left subtree is taller than the right. Which key is at the root?

  1. A. 13
  2. B. 21
  3. C. 17
  4. D. 20

Correct answer: B. 21

Minimum sizes satisfy N(h) = N(h-1) + N(h-2) + 1 from N(0) = 1, N(1) = 2: 1, 2, 4, 7, 12, 20, 33. So n = 33, and the root's subtrees must be minimum trees of heights 5 and 4, holding 20 and 12 keys. With the taller side on the left, the 20 smallest keys sit to the left of the root, which is key 21 in inorder (key 13 if the right side were taller).

More Programming and Data Structures (GATE) questions

Exams that ask this topic