login
A316944
Total height of the binary search trees summed over all permutations of [n].
5
0, 1, 4, 16, 80, 456, 3072, 23536, 202304, 1937920, 20470400, 236172288, 2955465216, 39893618688, 577937479680, 8944476580864, 147277509541888, 2570740210700288, 47418288632692736, 921669646969167872, 18829500772271472640, 403390045252173381632
OFFSET
0,3
COMMENTS
Each permutation of [n] generates a binary search tree of height h (floor(log_2(n))+1 <= h <= n) when its elements are inserted in that order into the initially empty tree. The average height of a binary search tree on n elements is A195582(n)/A195583(n).
Empty external nodes are counted in determining the height of a search tree.
FORMULA
a(n) = Sum_{k=0..n} k * A195581(n,k) = Sum_{k=0..n} k * A244108(n,k).
a(n) = A000142(n) * A195582(n)/A195583(n).
EXAMPLE
a(3) = 16 = 3 + 3 + (2+2) + 3 + 3:
.
3 3 2 1 1
/ \ / \ / \ / \ / \
2 o 1 o 1 3 o 3 o 2
/ \ / \ ( ) ( ) / \ / \
1 o o 2 o o o o 2 o o 3
/ \ / \ / \ / \
o o o o (2,1,3) o o o o
(3,2,1) (3,1,2) (2,3,1) (1,3,2) (1,2,3)
.
MAPLE
b:= proc(n, k) option remember; `if`(n<2, `if`(k<n, 0, 1),
add(binomial(n-1, r)*b(r, k-1)*b(n-1-r, k-1), r=0..n-1))
end:
a:= n-> add(k*(b(n, k)-b(n, k-1)), k=0..n):
seq(a(n), n=0..25);
MATHEMATICA
b[n_, k_] := b[n, k] = If[n < 2, If[k < n, 0, 1], Sum[Binomial[n - 1, r]* b[r, k - 1] b[n - 1 - r, k - 1], {r, 0, n - 1}]];
a[n_] := Sum[k(b[n, k] - b[n, k - 1]), {k, 0, n}];
a /@ Range[0, 25] (* Jean-François Alcover, Jan 27 2021, after Alois P. Heinz *)
KEYWORD
nonn
AUTHOR
Alois P. Heinz, Jul 17 2018
STATUS
approved