GATE Computer ScienceHardGATE CS

An AVL tree is a binary search tree in which the heights of the two subtrees of every node differ by at most 1. Taking the height of a single-node tree as 0, what is the maximum possible height of an AVL tree that has exactly 100 nodes?

  1. A. 9
  2. B. 7
  3. C. 10
  4. D. 8

Correct answer: D. 8

The fewest nodes an AVL tree of height h can have 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, 88, 143, ... Since N(8) = 88 ≤ 100 < 143 = N(9), the tallest AVL tree with 100 nodes has height 8.

More Algorithms questions

Exams that ask this topic