Where is the Successor?

We can derive a simple (?) rule for determining the node in the binary search tree that immediately follows node i in the sorted order (returns 0 for max element in tree):

1.
If tex2html_wrap_inline122 , tex2html_wrap_inline124 , then, while tex2html_wrap_inline126 , tex2html_wrap_inline128 . Return j.

2.
Otherwise, if tex2html_wrap_inline132 , return 0.

3.
Otherwise, if tex2html_wrap_inline136 , return tex2html_wrap_inline138 .

4.
Otherwise, tex2html_wrap_inline140 , then, while tex2html_wrap_inline142 and tex2html_wrap_inline144 , tex2html_wrap_inline146 . Return tex2html_wrap_inline148 (may be 0).

Running time in terms of the height of the tree?

How could this be used to delete an element from the tree?


next up previous
Next: Successive Insertions and Deletions Up: BINARY SEARCH TREES Previous: Listing Items in Order