GATE Computer ScienceHardGATE CS (PYQ pattern)

Height is counted in edges (a single node has height 0). What is the maximum possible height of an AVL tree with 50 nodes, and what is the minimum number of nodes in an AVL tree of height 7 whose root has balance factor 0?

  1. A. 7 and 67
  2. B. 6 and 54
  3. C. 5 and 67
  4. D. 6 and 67

Correct answer: D. 6 and 67

The sparsest AVL trees satisfy N(h) = N(h-1) + N(h-2) + 1 with N(0) = 1, N(1) = 2: 1, 2, 4, 7, 12, 20, 33, 54, ... N(6) = 33 <= 50 < N(7) = 54, so the height is at most 6. A root with balance 0 and height 7 needs two subtrees of height 6, each with at least 33 nodes: 33 + 33 + 1 = 67, more than the 54 of the sparsest height-7 tree.

More Programming and Data Structures (GATE) questions

Exams that ask this topic