0

I was coding up a Generic Treap data structure as an exercise, and then performed an analysis on the size (number of elements) of the treap, height of the treap, as well as the treap constant (height / log10(size)). I found that the height of my Treaps were almost always double the log2(size), which is double the expected height.

For example, inserting the same 934 elements (size = 934) in the treap 10 times, the height of the treap was around the range [19, 26], and my treap constant was roughly around 6-7.

Assuming my insertion, height, and randomPriority methods are all correct, might there be another reason that my Treap height is so tall?

I have also tried this with numerous data types and found that my heights were always around double the expected height.

  • 2
    *"I found that the height of my Treaps were almost always double the log2(size), which is double the expected height."* What is the reason for expecting that? The Wikipedia article on Treaps only says that the expected height is *proportional* to this logarithm, not equal to it; if you have some other source which says it should be equal, please cite it. Otherwise the error may just be that you are expecting the wrong thing. *"Assuming my insertion, height, and randomPriority methods are all correct"* - if you believe the height of your tree is wrong, then how can you assume this? – kaya3 Oct 15 '22 at 23:15
  • 1
    You're correct, I was assuming the wrong thing. Thank you for clarifying that for me. – idkusrname126 Oct 15 '22 at 23:53
  • The `log2(size)` is the _perfect_ height for a perfect heap. – Louis Wasserman Oct 16 '22 at 01:02

0 Answers0