Average height of a binary search tree

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

    Regardless of what tree you are using the average height will be log2(1000), as someone mentioned before. It's true that depending on the order of the numbers inserted the actual height may vary, but assuming randomly distributed numbers, which you mention, then the actual value will, more often than not, approximate the expected value (Which, once again, is log2(1000))

提交回复
热议问题