Data Structures & AlgorithmsHardTCS NQT · Infosys pattern

What is the minimum number of nodes in an AVL tree of height h (height of a single node = 0)?

What is the minimum number of nodes in an AVL tree of height h (height of a single node = 0)?
def n_min(h):
    a, b = 1, 2          # N(0), N(1)
    if h == 0: return 1
    for _ in range(2, h + 1): a, b = b, a + b + 1
    return b
print(n_min(3), n_min(5), n_min(1))
  1. A. 7 20 2
  2. B. 7 12 2
  3. C. 8 20 2
  4. D. 7 20 3

Correct answer: A. 7 20 2

A sparsest AVL tree of height h has a root, one subtree of height h − 1 and one of height h − 2: N(h) = N(h − 1) + N(h − 2) + 1 with N(0) = 1, N(1) = 2 → 1, 2, 4, 7, 12, 20. So height grows at most about 1.44 log₂ n, which keeps AVL operations O(log n).

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic