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

The ordered tree of any degree in \( 2 n + 1 \) bits by LOUDS, the level-order unary degree sequence of Jacobson (chapter 15, Compressed Data Structures, of Ferragina's book): a dummy root of degree 1 is put above the root, the nodes are visited by levels, and the degree \( d \) of each one is written in unary as \( 0^d 1 \), so that the code \( B \) has \( n \) 0s, one per node (each one is the child of somebody), and \( n + 1 \) 1s, one per node and the dummy root, i.e., \( 2 n + 1 \) bits. More...

#include "ADS/Contract.h"
#include "ADS/succinct/BitVector.h"
#include "ADS/succinct/RankSelect.h"
#include <cstddef>
#include <string_view>
#include <vector>
#include "ADS/succinct/impl/LoudsTree.tpp"

Go to the source code of this file.

Classes

class  ADS::LoudsTree
 an ordered tree in \( 2 n + 1 \) bits by LOUDS, its nodes by levels More...

Namespaces

namespace  ADS

Detailed description

The ordered tree of any degree in \( 2 n + 1 \) bits by LOUDS, the level-order unary degree sequence of Jacobson (chapter 15, Compressed Data Structures, of Ferragina's book): a dummy root of degree 1 is put above the root, the nodes are visited by levels, and the degree \( d \) of each one is written in unary as \( 0^d 1 \), so that the code \( B \) has \( n \) 0s, one per node (each one is the child of somebody), and \( n + 1 \) 1s, one per node and the dummy root, i.e., \( 2 n + 1 \) bits.

The \( k \)-th 0 is the \( k \)-th node by levels, and the children of the \( k \)-th node are the 0s after the \( ( k + 1 ) \)-th 1, the 1 of the dummy root counting first; hence, with rank and select [see RankSelect.h], in \( O( 1 ) \) time:

  • \( \mathrm{degree}( x ) = \mathrm{select}_1( x + 1 ) - \mathrm{select}_1( x ) - 1 \);
  • \( \mathrm{parent}( x ) = \mathrm{rank}_1( \mathrm{select}_0( x ) ) = \mathrm{select}_0( x ) - x \);
  • \( \mathrm{firstChild}( x ) = \mathrm{select}_1( x ) + 1 - x \), unless the degree is 0;
  • \( \mathrm{nextSibling}( x ) = x + 1 \) if the bit after \( \mathrm{select}_0( x ) \) is 0, none otherwise;

with the nodes and the places counted from 1, as in the same chapter; here they count from 0 (the root is the node 0, at the place 0 of \( B \)), and the functions are leftmostChild() and rightSibling(), with the names of the TREE of the book [see Tree.h]. The \( i \)-th child is the first one plus \( i \), since the children of a node are consecutive in the order by levels, which a visit in depth does not give. LOUDS does not answer the size of a subtree nor the depth of a node, which the parentheses of a visit in depth do [see BPTree.h], at the price of a range min-max tree; it is the simplest of the succinct trees and the fastest for the navigation from the root down (Arroyuelo, Cánovas, Navarro and Sadakane), e.g., in the tries of the indices.

The contracts [see Contract.h]: the lists of the children describe a tree rooted at 0, \( B \) is a code of LOUDS (\( n \) 0s and \( n + 1 \) 1s, no prefix with more 0s than 1s before the last 1, an audit), and the nodes are in \( [ 0 , n ) \). The functions are defined in LoudsTree.tpp.

See also
P. Ferragina, Pearls of Algorithm Engineering, Cambridge University Press, 2023, chapter 15, Compressed Data Structures, doi:10.1017/9781009128933
G. Jacobson, Space-efficient static trees and graphs, Proc. 30th FOCS, 549-554, 1989, doi:10.1109/SFCS.1989.63533
D. Arroyuelo, R. Cánovas, G. Navarro, K. Sadakane, Succinct trees in practice, Proc. 12th ALENEX, 84-97, 2010, doi:10.1137/1.9781611972900.9
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa