|
ADS
Algorithms and Data Structures
|
The binary tree of Jacobson in \( 2 n + 1 \) bits (chapter 15, Compressed Data Structures, of Ferragina's book): the tree of \( n \) nodes is completed with a leaf in place of each missing child, its \( 2 n + 1 \) nodes are visited by levels, and the code \( B \) gets a 1 for a node of the tree and a 0 for a leaf added. More...
#include "ADS/Contract.h"#include "ADS/succinct/BitVector.h"#include "ADS/succinct/RankSelect.h"#include <cstddef>#include <string_view>#include <utility>#include <vector>#include "ADS/succinct/impl/JacobsonTree.tpp"Go to the source code of this file.
Classes | |
| class | ADS::JacobsonTree |
| a binary tree in \( 2 n + 1 \) bits, its nodes by levels More... | |
Namespaces | |
| namespace | ADS |
The binary tree of Jacobson in \( 2 n + 1 \) bits (chapter 15, Compressed Data Structures, of Ferragina's book): the tree of \( n \) nodes is completed with a leaf in place of each missing child, its \( 2 n + 1 \) nodes are visited by levels, and the code \( B \) gets a 1 for a node of the tree and a 0 for a leaf added.
With the places counted from 1, the children of the \( x \)-th node by levels are at the places \( 2 x \) and \( 2 x + 1 \), as in a heap, since each node adds its two children to the visit; the node at the place \( p \) is the \( \mathrm{rank}_1( p ) \)-th one, and the \( x \)-th node is at the place \( \mathrm{select}_1( x ) \), a child of the \( \lfloor \mathrm{select}_1( x ) / 2 \rfloor \)-th one. Hence, with rank and select in \( O( 1 ) \) time [see RankSelect.h], left(), right() and parent() take \( O( 1 ) \) time, in \( 2 n + 1 + o( n ) \) bits, as Jacobson proves, against the \( \Theta( n \log n ) \) bits of the pointers. The \( 2 n - \Theta( \log n ) \) bits needed to tell apart the \( C_n \approx 4^n / ( n^{3/2} \sqrt{\pi} ) \) binary trees of \( n \) nodes show that the representation is within \( O( \log n ) \) bits of the optimum.
The nodes are numbered \( 0 , \ldots , n - 1 \) by levels, from the left; the node \( v \) is at the place \( \mathrm{select}_1( v + 1 ) \) of \( B \), counted from 0, and the data of the nodes, if any, go in a vector indexed by that number. The representation answers the navigation but not the size of a subtree, which needs the order of a visit in depth [see BPTree.h].
The contracts [see Contract.h]: the lists of the children describe a binary tree rooted at 0, and \( B \) is the code of a binary tree (\( 2 n + 1 \) bits, the \( x \)-th 1 before the places \( 2 x \) and \( 2 x + 1 \), an audit); the nodes are in \( [ 0 , n ) \). The functions are defined in JacobsonTree.tpp.