Minimum AVL Tree

An AVL tree is a rooted binary tree such that, for any node, the subtrees of its children have difference of height of at most 1. (An empty tree with no nodes has height 0, a tree with a single node has height 1.)

What is the fewest nodes an AVL tree with height 10 could have?


The answer is 143.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Ivan Koswara
Mar 29, 2016

Note that any subtree (a node together with all descendants of it) of an AVL tree is also an AVL tree. Consider an AVL tree of height n n . By definition of height, one of its subtrees must have height n 1 n-1 . Since it's an AVL tree, the other subtree must have height of at least n 2 n-2 .

Let a n a_n be the minimum number of nodes that an AVL tree of height n n can have. Clearly, a 0 = 0 , a 1 = 1 a_0 = 0, a_1 = 1 . The above observation shows that a n 1 + a n 1 + a n 2 a_n \ge 1 + a_{n-1} + a_{n-2} (1 node for the root, plus a n 1 a_{n-1} for the subtree with height n 1 n-1 , plus a n 2 a_{n-2} for the subtree with height at least n 2 n-2 ).

In fact, equality can be achieved by taking the smallest possibility; that is, to construct the minimum AVL tree of height n n , take two AVL trees of height n 1 n-1 and n 2 n-2 , and attach them as subtrees of the root. This works because the two subtrees don't interact other than the condition that their height difference is at most 1, and we have satisfied it by selecting one with height n 1 n-1 and one with height n 2 n-2 .

Thus, a n = 1 + a n 1 + a n 2 a_n = 1 + a_{n-1} + a_{n-2} . Following the recurrence gives a 10 = 143 a_{10} = \boxed{143} .

Additionally, consider b n = 1 + a n b_n = 1+a_n . We have b 0 = 1 , b 1 = 2 b_0 = 1, b_1 = 2 , and b n = b n 1 + b n 2 b_n = b_{n-1} + b_{n-2} for all n 2 n \ge 2 . This is the recurrence of the Fibonacci numbers, and in fact b n = F n + 2 b_n = F_{n+2} which can be proven easily by induction. Thus we obtain the general formula a n = F n + 2 1 a_n = F_{n+2} - 1 , explaining why a 10 = F 12 1 = 144 1 = 143 a_{10} = F_{12} - 1 = 144 - 1 = 143 .

Abhishek Sinha
Apr 1, 2016

Let N ( h ) N(h) denote minimum number of nodes in an AVL tree of height h h . A node in a rooted tree is at an height h h if and only if one of its child is at height h 1 h-1 and the other is at height at most h 1 h-1 . Since the height difference of the child at AVL tree does not exceed 1 1 , this leaves the following two possibilities :

(1) Both of its children are at height h 1 h-1

(2) One of its child is at height h 1 h-1 and the other is at height h 2 h-2 .

Hence we have the following dynamic programming recursion N ( h ) = 1 + min ( 2 N ( h 1 ) , N ( h 1 ) + N ( h 2 ) ) N(h)= 1+ \min \bigg( 2N(h-1) , N(h-1)+N(h-2)\bigg) This can be readily solved for h = 10 h=10 with the initial condition N ( 0 ) = 0 , N ( 1 ) = 1 N(0)=0, N(1)=1 .

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...