ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ThreadedTree.h File Reference

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

Detailed description

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

  1. The operations are defined in ThreadedTree.tpp.
See also
A. J. Perlis, C. Thornton, Symbol manipulation by threaded lists, Communications of the ACM 3(4), 195-204, 1960, doi:10.1145/367177.367202
D. E. Knuth, The Art of Computer Programming, vol. 1, 3rd ed., Addison-Wesley, 1997, section 2.3.1
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa