login
Cardinality of the set of possible heights of AVL trees with n (leaf-) nodes.
6

%I #39 Aug 14 2021 18:34:24

%S 1,1,1,1,1,1,1,2,1,1,1,1,2,2,2,2,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,1,2,

%T 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,2,2,2,2,

%U 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3

%N Cardinality of the set of possible heights of AVL trees with n (leaf-) nodes.

%C a(n) increases at Fibonacci numbers (A000045) and decreases at powers of 2 plus 1 (A000051) for n>=8.

%C a(n) is the height (number of nonzero elements) of column n of triangles A143897, A217298.

%H Alois P. Heinz, <a href="/A217710/b217710.txt">Table of n, a(n) for n = 1..50000</a>

%H Wikipedia, <a href="https://en.wikipedia.org/wiki/AVL_tree">AVL tree</a>

%H <a href="/index/Ro#rooted">Index entries for sequences related to rooted trees</a>

%F a(n) = A072649(n) - A029837(n).

%e a(8) = 2: We have 1 AVL tree with n=8 (leaf-) nodes of height 3 and 16 of height 4 (8 is both Fibonacci number and power of 2):

%e o o

%e / \ / \

%e o o o o

%e / \ / ) / \ / \

%e o o o N o o o o

%e / ) ( ) ( ) ( ) ( ) ( ) ( )

%e o N N N N N N N N N N N N N

%e ( )

%e N N

%p a:= proc(n) local j, p; for j from ilog[(1+sqrt(5))/2](n)

%p while combinat[fibonacci](j+1)<=n do od;

%p p:= ilog2(n);

%p j-p-`if`(2^p<n, 2, 1)

%p end:

%p seq(a(n), n=1..120);

%p # second Maple program:

%p a:= proc(n) option remember; `if`(n=0, 1, a(n-1)+

%p `if`((t-> issqr(t+4) or issqr(t-4))(5*n^2), 1, 0)-

%p `if`((t-> is(2^ilog2(t)=t))(n-1), 1, 0))

%p end:

%p seq(a(n), n=1..120); # _Alois P. Heinz_, Aug 14 2021

%t a[n_] := Module[{j, p}, For[j = Log[(1+Sqrt[5])/2, n] // Floor, Fibonacci[j+1] <= n, j++]; p = Log[2, n] // Floor; j-p-If[2^p < n, 2, 1]]; Table[a[n], {n, 1, 120}] (* _Jean-François Alcover_, Dec 30 2013, translated from Maple *)

%Y Cf. A000045, A000051, A000079, A029837, A072649, A143897, A217298.

%K nonn

%O 1,8

%A _Alois P. Heinz_, Mar 20 2013