I am creating a binary using tsearch(). Is the tree created balanced automatically. How can I verify the tree is balanced or unbalanced.
I looked into this some time ago while working on my own implementation of tsearch()
. For this API, it makes more sense to use an AVL tree than a Red-Black tree, as performing comparisons through a callback function has a pretty high overhead. AVL trees are more optimally balanced, meaning that the callback is invoked less frequently.
It seems that the definition of tsearch()
in POSIX does not require any balancing, so unfortunately you cannot assume that these functions perform well. What I observed while looking at some existing implementations:
tdelete()
to make the tree unbalanced.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With