|
ADS
Algorithms and Data Structures
|
The range minimum query, beyond the book: given an array \( A \) of \( n \) items of an ordered universe, the place of a minimum of \( A[ i .. j ] \) for any \( i \le j \), the leftmost one when the minimum repeats. More...
#include "ADS/Contract.h"#include <algorithm>#include <bit>#include <cstddef>#include <cstdint>#include <functional>#include <limits>#include <utility>#include <vector>#include "ADS/search/impl/RangeMinimum.tpp"Go to the source code of this file.
Classes | |
| class | ADS::SparseTable< T, Compare > |
| the range minima of an array by the sparse table More... | |
| class | ADS::PlusMinusOneRangeMinimum |
| the range minima of an array whose adjacent items differ by 1 More... | |
| class | ADS::RangeMinimum< T, Compare > |
| the range minima of an array by Bender and Farach-Colton: the Cartesian tree, its Euler tour, and the minima of the depths along the tour More... | |
Namespaces | |
| namespace | ADS |
Functions | |
| template<class T, class Compare = std::less< T >> | |
| std::vector< std::size_t > | ADS::cartesianTree (const std::vector< T > &A, Compare less={}) |
| the parent of each item of \( A \) in its Cartesian tree, the root (the leftmost minimum) having \( n \); equal items go to the right | |
The range minimum query, beyond the book: given an array \( A \) of \( n \) items of an ordered universe, the place of a minimum of \( A[ i .. j ] \) for any \( i \le j \), the leftmost one when the minimum repeats.
The problem is the backbone of the longest common extensions of a text [see SuffixArray.h] and of the lowest common ancestors of a tree [see SuffixTree.h].
The bound \( O( n ) \) of Bender and Farach-Colton was first reached by Harel and Tarjan on the lowest common ancestors, with a far more involved structure; Fischer and Heun need only \( 2 n + o( n ) \) bits besides \( A \), by describing each block by its own Cartesian tree, which removes the Euler tour and its factor 2. The sparse table is the simplest and, on the arrays that fit in a cache, often the fastest in practice.
The contracts [see Contract.h]: a query asks for \( i \le j < n \), and its answer is a leftmost minimum of the range (an audit, linear in the range); the items of a PlusMinusOneRangeMinimum differ by 1. The functions are defined in RangeMinimum.tpp.