Machine-translated by Google. Questions are authored in English.
Top

Discussion

Assuming that the height of a tree with a single node is 0, the maximum height of any AVL-tree with 7 nodes is

  • A.5
  • B.4
  • C.3
  • D.2

Answer: C

The maximum height is 3.

The tallest AVL tree with a given number of nodes is the sparsest one, in which the two subtrees of every node differ in height by exactly one. The minimum number of nodes \(N(h)\) in an AVL tree of height \(h\) is

\[ \begin{aligned} N(h) &= N(h-1) + N(h-2) + 1 \\ N(0) = 1,\ N(1) &= 2,\ N(2) = 4 \\ N(3) &= 7,\ N(4) = 12 \end{aligned} \]

A height of 4 needs at least 12 nodes, so 7 nodes can reach height 3 but not 4. Heights 4 and 5 are impossible with 7 nodes, and 2 is not the maximum.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.