Re: Non-recursive chop and clone for Binary Search Tree - Solutions



In article <9eb91415-ef51-4fb2-a734-b894fa88c573@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"jehugaleahsa@xxxxxxxxx" <jehugaleahsa@xxxxxxxxx> writes:

At the time, I wasn't in the mood; however, I was recently REQUIRED to
figure it out. The problem: I had an unbalanced tree that needed
destroyed. You can usually get away with a recursive (naive/trivial)
implementation, but you're leaving yourself open for a stack overflow
at some point down the line.


Why? Stack/resursion depth is bounded by the height of the tree. A
decent BST will use some form of balancing, which should keep the height
down to a few dozen levels or so.
.


Quantcast