login
Total number of elements in all permutations of [n], [n+1], ... that result in a binary search tree of height n.
5

%I #17 Jan 27 2021 10:14:43

%S 0,1,10,1316,840124672,6110726696100443604557936,

%T 439451426203104201222708341688051362423089952907263634936946272224

%N Total number of elements in all permutations of [n], [n+1], ... that result in a binary search tree of height n.

%C Empty external nodes are counted in determining the height of a search tree.

%H Alois P. Heinz, <a href="/A317012/b317012.txt">Table of n, a(n) for n = 0..9</a>

%H Wikipedia, <a href="https://en.wikipedia.org/wiki/Binary_search_tree">Binary search tree</a>

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

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

%F a(n) = Sum_{k=n..2^n-1} k * A195581(k,n) = Sum_{k=n..2^n-1} k * A244108(k,n).

%e a(2) = 10 = 2 + 3 + 3 + 2:

%e .

%e 2 2 1

%e / \ / \ / \

%e 1 o 1 3 o 2

%e / \ ( ) ( ) / \

%e o o o o o o o o

%e (2,1) (2,1,3) (2,3,1) (1,2)

%e .

%p b:= proc(n, k) option remember; `if`(n<2, `if`(k<n, 0, 1),

%p add(binomial(n-1, r)*b(r, k-1)*b(n-1-r, k-1), r=0..n-1))

%p end:

%p T:= (n, k)-> b(n, k)-b(n, k-1):

%p a:= k-> add(T(n, k)*n, n=k..2^k-1):

%p seq(a(n), n=0..6);

%t b[n_, k_] := b[n, k] = If[n < 2, If[k < n, 0, 1],

%t Sum[Binomial[n-1, r] b[r, k-1] b[n-1-r, k-1], {r, 0, n-1}]];

%t T[n_, k_] := b[n, k] - b[n, k-1];

%t a[k_] := Sum[T[n, k] n, {n, k, 2^k - 1}];

%t a /@ Range[0, 6] (* _Jean-François Alcover_, Jan 27 2021, after _Alois P. Heinz_ *)

%Y Cf. A195581, A227822, A244108, A335922.

%K nonn

%O 0,3

%A _Alois P. Heinz_, Jul 18 2018