|
ADS
Algorithms and Data Structures
|
the range minima of an array whose adjacent items differ by 1 More...
#include <ADS/search/RangeMinimum.h>
Public member functions | |
| PlusMinusOneRangeMinimum (void)=default | |
| an empty structure | |
| PlusMinusOneRangeMinimum (std::vector< long > D) | |
| the blocks, their sparse table and the table of the signatures, \( O( n ) \) | |
| std::size_t | query (std::size_t i, std::size_t j) const |
| the place of the leftmost minimum of \( D[ i .. j ] \), \( O( 1 ) \) | |
| std::size_t | size (void) const |
| the number \( n \) of the items | |
| std::size_t | blockSize (void) const |
| the number of items in a block | |
the range minima of an array whose adjacent items differ by 1
|
default |
an empty structure
|
explicit |
the blocks, their sparse table and the table of the signatures, \( O( n ) \)
In pseudocode (Bender and Farach-Colton, beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{build}( D ) \cr 2 & \quad d \gets \max\{ 1 , \lfloor \log_2 n \rfloor / 2 \} \cr 3 & \quad \textbf{foreach}\ \text{block } k \text{ of } d \text{ items} \ \textbf{do} \cr 4 & \qquad \mathit{sig}[ k ] \gets \text{the bits of its rises, those } \text{past the end set} \cr 5 & \qquad \mathit{min}[ k ] \gets \text{the place of its leftmost } \text{minimum} \cr 6 & \quad T \gets \text{the sparse table of the minima of the blocks} \cr 7 & \quad \textbf{foreach}\ \sigma < 2^{d-1} \text{ and } a \le b < d \ \textbf{do} \cr 8 & \qquad \mathit{table}[ \sigma ][ a ][ b ] \gets \text{the leftmost } \text{minimum of the walk } \sigma \text{ from } a \text{ to } b \end{array}} \]
|
inlinenodiscard |
the number of items in a block
|
nodiscard |
the place of the leftmost minimum of \( D[ i .. j ] \), \( O( 1 ) \)
In pseudocode (Bender and Farach-Colton, beyond the book), the leftmost of the smallest of at most three minima:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{query}( i , j ) \cr 2 & \quad b_i \gets \lfloor i / d \rfloor;\ b_j \gets \lfloor j / d \rfloor \cr 3 & \quad \textbf{if}\ b_i = b_j\ \textbf{then return}\ b_i d + \mathit{table}[ \mathit{sig}[ b_i ] ][ i \bmod d ][ j \bmod d ] \cr 4 & \quad r \gets \text{the minimum of the suffix of block } b_i \text{ from } i \cr 5 & \quad \textbf{if}\ b_j > b_i + 1\ \textbf{then}\ r \gets \text{the better of } r \text{ and } \mathit{min}[ T.\mathrm{query}( b_i + 1 , b_j - 1 ) ] \cr 6 & \quad \textbf{return}\ \text{the better of } r \text{ and the } \text{minimum of the prefix of } b_j \text{ to } j \end{array}} \]
|
inlinenodiscard |
the number \( n \) of the items