Average height of a binary search tree

后端 未结 7 2331
执笔经年
执笔经年 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:49

    It depends on whether you are using any sort of balanced tree structure (such as a red-black tree). Since you are inserting random numbers into a binary tree, it would be reasonable to expect that the average depth is approximately log2(1000) - so the values 10 and 11 would be 'normal'. I'm not sure how far it could deviate from that; no shallower than 10 levels, possibly somewhat deeper. An extreme case with no balancing would be 1000 deep; that is unlikely to happen with random numbers.

提交回复
热议问题