Average height of a binary search tree

后端 未结 7 2330
执笔经年
执笔经年 2021-01-03 04:19

How do you compute the average height of a binary search tree when adding 1000 random ints? What is the average height?

相关标签:
7条回答
  • 2021-01-03 04:54

    This question is in fact, tricky. The answer will not be 1000, because that is improbable, but log2(1000) is also improbable, but even more so depending on how the tree is grown.

    If you add an int by stepping though the tree then naively appending it the tree will virtually always be taller than log2(1000).

    Talk to a statistician, because this seems related to normal probability distributions. Those are generated by lots of iterated random events( heads one unit right, tails ditto left), and the value of a random integer iterates through the tree as it settles out into a leaf.

    0 讨论(0)
提交回复
热议问题