avatar
请教一个binary tree问题# JobHunting - 待字闺中
t*g
1
一个unbalanced binary tree
每个节点记录一个整数
对每个节点值
左边的child小于当前节点
右边的child大于当前节点
所以你插入1,2,3,4,5...n,会得到一个depth=n的树
可是插入6,4,8,3,5,7,9,就会得到一个well balanced tree
问题:
What is the average asymptotic depth of a simple unbalanced search tree of
integers? Use O(n) notation and provide proof
avatar
g*y
2
h(n) = 1 + 1/n * SUM{ max(h(i), h(n-1-i) } where i=0....n-1
max( h(i) , h(n-1-i) ) = h(max(i , n-1-i))
=>
h(n) = 1 + 2/n * SUM{ h(n/2+i) } where i=0...n/2-1
= 1 + < h(x) > where x = n/2 ... n with uniform distribution
then I am not quite sure about a strict math proof, but you can definitely "
try" the solution to prove it is O(logn)
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。