|
|||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||
A threaded binary tree may be defined as follows:
(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 the binary tree via a linear traversal that is more rapid than a recursive in-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 ( In Python: def parent(node): if node is node.tree.root: return None else: x = node y = node while True: if is_thread(y.right): p = y.right if p is None or p.left is not node: p = x while not is_thread(p.left): p = p.left p = p.left return p elif is_thread(x.left): p = x.left if p is None or p.left is not node: p = y while not is_thread(p.right): p = p.right p = p.right return p x = x.left y = y.right External links |
| Strona • Strona • Strona • Ada • Grzyby • wały uprawowe • dalmierz laserowy • dalmierz • Alicja • Elwira • Angelika • Alina • Ania • Berta • Celina All Right Reserved © 2007, Designed by Stylish Blog. |