Explanation about threaded binary search trees (skip it if you know them):
We know that in a binary search tree with n nodes, there are n + 1 pointers left and right that contain null. To use this memory containing zero, we change the binary tree as follows:
for each node z in the tree:
if left [z] = NULL, we put left [z] the value of tree-predecessor (z) (that is, a pointer to a node that contains the predecessor key),
if right [z] = NULL, we will put the value tree-successor (z) to the right [z] (again, this is a pointer to a node that contains the successor key).
A tree like this is called a carved tree , and new links are called threads .
And my question is: What is the main advantage of threaded binary search trees (compared to βregularβ binary search trees). A quick search on the Internet told me that it helps to crawl in an iterative manner rather than a recursive manner.
Is that the only difference? Is there any other way to use threads?
Is this such a significant advantage? and if so, why? The recursive bypass time is O (n) too, so ..
Thank you very much.
source share