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

The treap that stores no priorities (exercise 7.6 of Morin), beyond the book: the treap of Seidel and Aragon [see Treap.h] whose priority of a node is the simple tabulation hash of its address [see RandomHashing.h], computed when needed, so that a node keeps only its pair and its two links. More...

#include "ADS/Contract.h"
#include "ADS/Iterators.h"
#include "ADS/dictionary/RandomHashing.h"
#include <algorithm>
#include <concepts>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <optional>
#include <utility>
#include "ADS/tree/BinaryTreeAlgorithms.h"
#include "ADS/tree/impl/HashedTreap.tpp"

Go to the source code of this file.

Classes

class  ADS::HashedTreap< K, V >
 a DICTIONARY on a treap whose priorities are the hashes of the addresses of the nodes More...
struct  ADS::HashedTreap< K, V >::Shape
 the shape of the tree, for PathIterator More...

Namespaces

namespace  ADS

Detailed description

The treap that stores no priorities (exercise 7.6 of Morin), beyond the book: the treap of Seidel and Aragon [see Treap.h] whose priority of a node is the simple tabulation hash of its address [see RandomHashing.h], computed when needed, so that a node keeps only its pair and its two links.

It is a DICTIONARY [see ADT.h] with the find(x) of an SSet (lowerBound()), and its operations are those of Treap: an insertion goes down to a leaf and rotates the new node up while its priority beats its parent's, a removal rotates the node down until it has one child at most.

For the analysis of the treap to hold the priorities must behave as random and independent of the keys, which a fixed function of the addresses does not guarantee; the proof of Lemma 7.1 of Morin needs that, among any \( k \) nodes, each has the largest priority with probability \( O( 1 / k ) \) (the min-wise independence of the discussion of section 7.3 of Morin), and the simple tabulation hashing of words of 8 characters, its tables drawn from the seed, gives each of \( k \) addresses the extreme hash with probability \( ( 1 \pm \epsilon ) / k \), \( \epsilon = O( \log^2 k / k^{1/8} ) \) (Theorem 3 of Pătraşcu and Thorup, for the minimum, and the maximum is the minimum of the complements), i.e., \( O( 1 / k ) \); hence the expected depth stays \( O( \log n ) \), whatever the keys and the order of the operations, as long as they do not depend on the tables. The shape depends on the addresses that the allocator gives, so that two runs build the same set into different trees.

Where it is meant to differ from the Treap of Morin, for the benchmarks to check: a node is smaller by the priority and the parent, which may make it fit a smaller class of the allocator; the price is a hash of 8 lookups in a table of 16 KB, two per level climbed by the new node, which stops at the first parent of larger priority (fewer than 2 rotations on average with independent priorities), and two per rotation of a removal.

The contracts [see Contract.h]: insert() ensures that the key is there and remove() that it is not; the invariant is the order of the keys and the heap order of the hashes, an \( O( n ) \) check at the level 3. The operations are defined in HashedTreap.tpp.

See also
R. Seidel, C. R. Aragon, Randomized search trees, Algorithmica 16(4-5), 464-497, 1996, doi:10.1007/BF01940876
M. Pătraşcu, M. Thorup, The power of simple tabulation hashing, Journal of the ACM 59(3), 14:1-14:50, 2012, doi:10.1145/2220357.2220361
P. Morin, Open Data Structures (in C++), Edition 0.1G, 2013, https://opendatastructures.org/ods-cpp.pdf, sections 7.2 and 7.3 and exercise 7.6
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa