Quantcast
Channel: Recursive formula for height of BST - Computer Science Stack Exchange
Viewing all articles
Browse latest Browse all 3

Recursive formula for height of BST

$
0
0

Let $H(n)$ be the average height of a BST with nodes from ${1,...,n}$. I think that$$H(n) = \frac{1}{n}\sum_{i = 0}^{n-1}\left[\text{max}(H(i), H(n-1 -i)) + 1\right]$$But I don't know how to prove this is correct. Can anyone help me or explain why this is incorrect?

Note proving it directly seems hard because you end up with E[max(X, Y)] where X is height of left subtree and Y height of right subtree. I'm not really sure how to deal with this if we're looking for an exact recursion, not just a bound.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles



Latest Images