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...
|
| | RangeMinimum (void)=default |
| | an empty structure
|
| | RangeMinimum (std::vector< T > A, Compare less={}) |
| | the structure of \( A \), \( O( n ) \)
|
| std::size_t | query (std::size_t i, std::size_t j) const |
| | the place of the leftmost minimum of \( A[ i .. j ] \), \( O( 1 ) \)
|
| std::size_t | size (void) const |
| | the number \( n \) of the items
|
| const T & | operator[] (std::size_t i) const |
| | the item of place \( i \)
|
| const std::vector< std::size_t > & | eulerTour (void) const |
| | the nodes of the Euler tour of the Cartesian tree, \( 2 n - 1 \) of them
|
| const_iterator | begin (void) const |
| | the first item
|
| const_iterator | end (void) const |
| | past the last item
|
| const_iterator | cbegin (void) const |
| | the first item
|
| const_iterator | cend (void) const |
| | past the last item
|
template<class T, class Compare = std::less< T >>
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
template<class T, class Compare = std::less< T >>
| ADS::RangeMinimum< T, Compare >::RangeMinimum |
( |
std::vector< T > | A, |
|
|
Compare | less = {} ) |
|
explicit |
the structure of \( A \), \( O( n ) \)
In pseudocode (Bender and Farach-Colton, beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{build}( A ) \cr
2 & \quad P \gets \mathrm{cartesianTree}( A ) \cr
3 & \quad E , D \gets \text{the nodes and the depths of the Euler tour}
\text{ of } P \cr
4 & \quad \mathit{first}[ v ] \gets \text{the first place of } v
\text{ in } E \text{, for each } v \cr
5 & \quad \text{build the } \pm 1 \text{ structure on } D
\end{array}}
\]
template<class T, class Compare = std::less< T >>
| std::size_t ADS::RangeMinimum< T, Compare >::query |
( |
std::size_t | i, |
|
|
std::size_t | j ) const |
|
nodiscard |
the place of the leftmost minimum of \( A[ i .. j ] \), \( O( 1 ) \)
In pseudocode (Bender and Farach-Colton, beyond the book), the lowest common ancestor of \( i \) and \( j \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{query}( i , j ) \cr
2 & \quad a \gets \min\{ \mathit{first}[ i ] , \mathit{first}[ j ] \};
\ b \gets \max\{ \mathit{first}[ i ] , \mathit{first}[ j ] \} \cr
3 & \quad \textbf{return}\ E[ \text{the } \pm 1 \text{ query on } D[ a ..
b ] ]
\end{array}}
\]
- Precondition
- \( i \le j < n \)
- Postcondition
- a leftmost minimum of \( A[ i .. j ] \) (audit)