Skip to content
Official PYQ · 2009

GATE CS 2009 Q37 — Binary Search Trees

Explain with AI

What is the maximum height of any AVL-tree with 77 nodes? Assume that the height of a tree with a single node is 00.

Choose one option
View worked solution

Answer: B

To find the maximum height of an AVL tree with n=7n = 7 nodes, we can determine the minimum number of nodes required to construct an AVL tree of height hh, denoted as N(h)N(h).

Given that the height of a single-node tree is 00:

  • For h=0h = 0: N(0)=1N(0) = 1 (a single root node)
  • For h=1h = 1: N(1)=2N(1) = 2 (a root with one child)

For any height h≥2h \ge 2, an AVL tree of minimum size consists of a root, one subtree of height h−1h-1 with minimum nodes, and another subtree of height h−2h-2 with minimum nodes. This gives the recurrence relation:

N(h)=N(h−1)+N(h−2)+1N(h) = N(h-1) + N(h-2) + 1

Using this recurrence, we compute the minimum nodes for successive heights:

  • N(2)=N(1)+N(0)+1=2+1+1=4N(2) = N(1) + N(0) + 1 = 2 + 1 + 1 = 4
  • N(3)=N(2)+N(1)+1=4+2+1=7N(3) = N(2) + N(1) + 1 = 4 + 2 + 1 = 7
  • N(4)=N(3)+N(2)+1=7+4+1=12N(4) = N(3) + N(2) + 1 = 7 + 4 + 1 = 12

Since we have exactly 77 nodes, the maximum height we can achieve is 33 (which requires exactly 77 nodes). A height of 44 would require at least 1212 nodes.

Thus, the maximum height of an AVL tree with 77 nodes is 3.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Binary Search Trees questions