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

The ordered tree of any degree in \( 2 n \) bits by its balanced parentheses: a visit in depth writes an open parenthesis when it enters a node and a closed one when it leaves it, so that a node is the pair of its parentheses and its subtree is what they enclose (the code with which chapter 15, Compressed Data Structures, of Ferragina's book counts the trees of \( n \) nodes). More...

#include "ADS/Contract.h"
#include "ADS/succinct/BalancedParentheses.h"
#include "ADS/succinct/BitVector.h"
#include <cstddef>
#include <string_view>
#include <utility>
#include <vector>
#include "ADS/succinct/impl/BPTree.tpp"

Go to the source code of this file.

Classes

class  ADS::BPTree
 an ordered tree in \( 2 n \) bits by balanced parentheses, its nodes in preorder More...

Namespaces

namespace  ADS

Detailed description

The ordered tree of any degree in \( 2 n \) bits by its balanced parentheses: a visit in depth writes an open parenthesis when it enters a node and a closed one when it leaves it, so that a node is the pair of its parentheses and its subtree is what they enclose (the code with which chapter 15, Compressed Data Structures, of Ferragina's book counts the trees of \( n \) nodes).

The nodes are numbered in preorder, the node \( v \) being the \( ( v + 1 ) \)-th open parenthesis, at the place \( \mathrm{select}_1( v + 1 ) \), and with the matching of the parentheses [see BalancedParentheses.h]:

  • parent( v ) is enclose() of its open parenthesis, leftmostChild( v ) is \( v + 1 \) if the next parenthesis is an open one, and rightSibling( v ) the open parenthesis after its closed one, if any;
  • subtreeSize( v ) is \( ( j - i + 1 ) / 2 \) for its parentheses at \( i \) and \( j \), depth( v ) is the excess at its open parenthesis less 1, and \( u \) is an ancestor of \( v \) if the open parenthesis of \( v \) is between the parentheses of \( u \);

in the time of a search in the range min-max tree, \( O( \log ( n / 8192 ) ) \) plus the scan of a group and of a leaf, and in the time of a select and of a rank for leftmostChild(), depth() and isLeaf(). Against LOUDS [see LoudsTree.h], the parentheses also give the size of a subtree, the depth and the ancestors, and number the nodes of a subtree consecutively (from \( v \) to \( v + \mathrm{subtreeSize}( v ) - 1 \)), at the price of the searches; DFUDS of Benoit, Demaine, Munro, Raman, Raman and Rao, the degrees in unary in preorder, also gives the \( i \)-th child in \( O( 1 ) \) time with the same matching, which the same chapter does not treat.

The contracts [see Contract.h]: the lists of the children describe a tree rooted at 0, the parentheses are balanced and enclose one tree, and the nodes are in \( [ 0 , n ) \). The functions are defined in BPTree.tpp.

See also
P. Ferragina, Pearls of Algorithm Engineering, Cambridge University Press, 2023, chapter 15, Compressed Data Structures, doi:10.1017/9781009128933
J. I. Munro, V. Raman, Succinct representation of balanced parentheses and static trees, SIAM Journal on Computing 31(3), 762-776, 2001, doi:10.1137/S0097539799364092
D. Benoit, E. D. Demaine, J. I. Munro, R. Raman, V. Raman, S. S. Rao, Representing trees of higher degree, Algorithmica 43(4), 275-292, 2005, doi:10.1007/s00453-004-1146-6
G. Navarro, K. Sadakane, Fully functional static and dynamic succinct trees, ACM Transactions on Algorithms 10(3), 16, 2014, doi:10.1145/2601073
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa