- Threaded binary tree
A threaded
binary tree may be defined as follows:A binary tree is "threaded" by making all right child pointers that would normally be null point to the inorder successor of the node, and all left child pointers that would normally be null point to the inorder predecessor of the node."
(Van Wyk, Christopher J. Data Structures and C Programs, Addison-Wesley, 1989, p. 175. ISBN 978-0-201-16116-8.)A threaded
binary tree makes it possible to traverse the values in thebinary tree via a linear traversal that is more rapid than a recursivein-order traversal .It is also possible to discover the parent of a node from a threaded binary tree, without explicit use of parent pointers or a stack, albeit slowly. This can be useful where stack space is limited, or where a stack of parent pointers is unavailable (for finding the parent pointer via DFS).
This is possible, because if a node (
k
) has a right child (m
) thenm
's left pointer must be either a child, or a thread back tok
. In the case of a left child, that left child must also have a left child or a thread back tok
, and so we can followm
's left children until we find a thread, pointing back tok
. The situation is similar for whenm
is the left child ofk
In Python:
External links
* [http://www.eternallyconfuzzled.com/tuts/datastructures/jsw_tut_bst1.aspx#thread Tutorial on threaded binary trees]
* [http://www.stanford.edu/~blp/avl/libavl.html/Threaded-Binary-Search-Trees.html GNU libavl 2.0.2, Section on threaded binary search trees]
Wikimedia Foundation. 2010.