|
ADS
Algorithms and Data Structures
|
The threaded binary search tree of Perlis and Thornton, beyond the book: a missing left child is replaced by a link (a thread) to the predecessor in symmetric order, and a missing right child by a thread to the successor, a bit of each node telling a child from a thread; the symmetric visit then needs neither a stack nor the recursion, the successor of a node being its right thread or the leftmost node of its right subtree (Algorithm S of Knuth, section 2.3.1), in \( O( 1 ) \) amortized time each. More...
#include "ADS/Contract.h"#include "ADS/Iterators.h"#include <concepts>#include <cstddef>#include <iterator>#include <vector>#include "ADS/tree/impl/ThreadedTree.tpp"Go to the source code of this file.
Classes | |
| class | ADS::ThreadedTree< K > |
| a binary search tree with threads in symmetric order More... | |
| class | ADS::ThreadedTree< K >::const_iterator |
| the constant iterator in symmetric order, by the threads More... | |
Namespaces | |
| namespace | ADS |
The threaded binary search tree of Perlis and Thornton, beyond the book: a missing left child is replaced by a link (a thread) to the predecessor in symmetric order, and a missing right child by a thread to the successor, a bit of each node telling a child from a thread; the symmetric visit then needs neither a stack nor the recursion, the successor of a node being its right thread or the leftmost node of its right subtree (Algorithm S of Knuth, section 2.3.1), in \( O( 1 ) \) amortized time each.
A head node, whose left child is the root and which is the predecessor of the first node and the successor of the last one, closes the threads, as in the representation of Knuth.
The contracts [see Contract.h]: insert() ensures that the key is there; the invariant is that the visit by threads gives the keys in increasing order, size() of them, an \( O( n ) \) check at the level