cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A228152 Triangle read by rows: T(n,k) = maximal external path length of AVL trees of height n with k (leaf-) nodes, n>=0, fibonacci(n+2)<=k<=2^n.

This page as a plain text file.
%I A228152 #39 Dec 17 2018 09:13:46
%S A228152 0,2,5,8,12,16,20,24,25,30,35,40,44,49,54,59,64,50,56,62,68,73,79,85,
%T A228152 91,97,102,107,113,119,125,131,136,142,148,154,160,96,103,110,117,123,
%U A228152 130,137,144,151,157,163,170,177,184,191,197,204,211,218,225,231
%N A228152 Triangle read by rows: T(n,k) = maximal external path length of AVL trees of height n with k (leaf-) nodes, n>=0, fibonacci(n+2)<=k<=2^n.
%C A228152 The external path length of a tree is the sum of the levels of its external nodes (i.e. leaves).
%D A228152 D. E. Knuth, Art of Computer Programming, Vol. 3, Sect. 6.2.3 (7) and (8).
%H A228152 Alois P. Heinz, <a href="/A228152/b228152.txt">Rows n = 0..12, flattened</a>
%H A228152 R. C. Richards, <a href="http://dx.doi.org/10.1016/0020-0190(83)90085-6">Shape distribution of height-balanced trees</a>, Info. Proc. Lett., 17 (1983), 17-20.
%H A228152 Wikipedia, <a href="http://en.wikipedia.org/wiki/AVL_tree">AVL tree</a>
%H A228152 <a href="/index/Ro#rooted">Index entries for sequences related to rooted trees</a>
%e A228152 T(2,3) = 5 because in the (two) AVL trees of height 2 with 3 (leaf-) nodes one has depth 1 and two have depth 2:
%e A228152        o       o
%e A228152       / \     / \
%e A228152      o   1   1   o
%e A228152     / \         / \
%e A228152    2   2       2   2
%e A228152 so that the sum of depths is 5 for both trees.
%e A228152 Triangle begins:
%e A228152   0
%e A228152   . 2
%e A228152   . . 5 8
%e A228152   . . . . 12 16 20 24
%e A228152   . . . .  .  .  . 25 30 35 40 44 49 54 59 64
%e A228152   . . . .  .  .  .  .  .  .  .  . 50 56 62 68 73 79 85 91 97 102 ...
%e A228152   . . . .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 96 103 ...
%p A228152 with(combinat): F:=fibonacci:
%p A228152 T:= proc(n, k) option remember; `if`(n<1, 0, max(seq([k+T(n-1,t)+
%p A228152       T(n-1,k-t), k+T(n-1,t) +T(n-2,k-t)][], t=F(n+1)..k-1)))
%p A228152     end:
%p A228152 seq(seq(T(n, k), k=F(n+2)..2^n), n=0..7);  # _Alois P. Heinz_, Aug 14 2013
%t A228152 maxNods = 100; Clear[T, A029837, A072649, A036289, A228155]; T[0, 1] = 0; A029837[1] = 0; A072649[1] = 1; A228155[1] = 0; For[k = 2, k <= maxNods, k++, A029837[k] = maxNods; A072649[k] = 0; A228155u = 0; For[kL = 1, kL <= Floor[k/2], kL++, For[hL = A029837[kL], hL <= A072649[kL] - 1, hL++, For[hR = Max[hL - 1, A029837[k - kL]], hR <= Min[hL + 1, A072649[k - kL] - 1], hR++, maxDepthSum = k + T[hL, kL] + T[hR, k - kL]; A228155u = Max[maxDepthSum, A228155u]; h = Max[hL, hR] + 1; If[ !IntegerQ[T[h, k]], T[h, k] = maxDepthSum, T[h, k] = Max[maxDepthSum, T[h, k]]]; A029837[k] = Min[h, A029837[k]]; If[ !IntegerQ[A036289[h]], A036289[h] = maxDepthSum, A036289[h] = Max[maxDepthSum, A036289[h]]]; A072649[k] = Max[h + 1, A072649[k]]; ]]]; A228155[k] = A228155u]; k =.; Table[T[n, k], {n, 0, maxNods}, {k, 1, maxNods}] // Flatten // Select[#, IntegerQ]& (* _Jean-François Alcover_, Aug 14 2013, translated and adapted from Herbert Eberle's MuPAD program *)
%o A228152 (MuPAD)
%o A228152 maxNods:=100: // max number of leaves (= external nodes)
%o A228152 // Triangle T for all AVL trees with <= maxNods leaves:
%o A228152 delete T:
%o A228152 // table T indexed [h, k] (h=height, k=number of leaves):
%o A228152 T[0, 1]:=0:
%o A228152 // A029837 indexed [k], min height of tree with k leaves:
%o A228152 A029837:=array(1..maxNods): A029837[1]:=0:
%o A228152 // A072649 indexed [k], 1+max height of AVL tree with k leaves:
%o A228152 A072649:=array(1..maxNods): A072649[1]:=1:
%o A228152 // A036289 indexed [h], max depthsum of all height h AVL trees:
%o A228152 A036289:=array(1..maxNods):
%o A228152 // A228155 indexed [k], max depthsum of all AVL trees with k leaves:
%o A228152 A228155:=array(1..maxNods): A228155[1]:=0:
%o A228152 for k from 2 to maxNods do:
%o A228152   A029837[k]:=maxNods: // try infinity for the min height
%o A228152   A072649[k]:=0:
%o A228152   A228155u:=0:
%o A228152   // Put together 2 AVL trees:
%o A228152   for kL from 1 to floor(k/2) do:
%o A228152     // kL leaves in the left tree
%o A228152     for hL from A029837[kL] to A072649[kL]-1 do:
%o A228152       for hR from max(hL-1, A029837[k-kL])
%o A228152                to min(hL+1, A072649[k-kL]-1) do:
%o A228152         // k-kL leaves in the right subtree
%o A228152         maxDepthSum:=T[hL, kL]+T[hR, k-kL]+k:
%o A228152         A228155u:=max(maxDepthSum, A228155u):
%o A228152         h:=max(hL, hR)+1:
%o A228152         if type(T[h, k]) <> DOM_INT then // T[h, k] uninit
%o A228152           T[h, k]:=maxDepthSum:
%o A228152         else
%o A228152           T[h, k]:=max(maxDepthSum, T[h, k]):
%o A228152         end_if:
%o A228152         A029837[k]:=min(h, A029837[k]):
%o A228152         if type(A036289[h]) <> DOM_INT then
%o A228152           A036289[h]:=maxDepthSum:
%o A228152         else
%o A228152           A036289[h]:=max(maxDepthSum, A036289[h]):
%o A228152         end_if:
%o A228152         A072649[k]:=max(h+1, A072649[k]):
%o A228152       end_for: // hR
%o A228152     end_for: // hL
%o A228152   end_for: // kL
%o A228152   A228155[k]:=A228155u:
%o A228152 end_for: // k
%Y A228152 Row maxima give: n*2^n = A036289(n).
%Y A228152 Row minima give: A067331(n-1) for n>0 or A166106(n+2).
%Y A228152 Row lengths give: 1+A008466(n).
%Y A228152 Number of AVL trees read by rows gives: A143897.
%Y A228152 Triangle read by columns gives: A228153.
%Y A228152 The infimum of all external path lengths of binary trees with k (leaf-) nodes is: A003314(k) for k>0.
%Y A228152 Column maxima give: A228155(k).
%Y A228152 Column heights give: A217710(k).
%Y A228152 Number of AVL trees read by columns gives: A217298.
%K A228152 nonn,tabf
%O A228152 0,2
%A A228152 _Herbert Eberle_, Aug 13 2013