TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
data_structures::sparse_table::Sparse_table Struct Reference
Collaboration diagram for data_structures::sparse_table::Sparse_table:
[legend]

Public Member Functions

int64_t query (int64_t l, int64_t r)
 Queries the sparse table for the value of the interval [l, r] (i.e. from l to r inclusive).
 

Public Attributes

size_t n = 0
 size of input array.
 
std::array< int64_t, NA = {}
 input array to perform RMQ.
 
std::array< std::array< int64_t, N >, MST {}
 the sparse table storing min() values for given interval.
 
std::array< int64_t, NLOG = {}
 where floor(log2(i)) are precomputed.
 

Detailed Description

Definition at line 51 of file sparse_table.cpp.

Member Function Documentation

◆ query()

int64_t data_structures::sparse_table::Sparse_table::query ( int64_t l,
int64_t r )
inline

Queries the sparse table for the value of the interval [l, r] (i.e. from l to r inclusive).

Parameters
lthe left index of the range (inclusive).
rthe right index of the range (inclusive).
Returns
the computed value of the given interval. @complexity: O(1)

< smallest power of 2 covering [l,r]

< represents minimum value over the range [g,l]

< represents minimum value over the range [g, r - pow(2,g) + 1]

< represents minimum value over the whole range [l,r]

Definition at line 110 of file sparse_table.cpp.

110 {
111 int64_t g = LOG[r - l + 1];
112 int64_t x = ST[g][l];
114 int64_t y =
115 ST[g][r - (1 << g) + 1];
117
118 return (A[x] <= A[y] ? x : y);
120 }
double g(double x)
Another test function.
double l(double x)
Another test function.
std::array< int64_t, N > LOG
where floor(log2(i)) are precomputed.
std::array< int64_t, N > A
input array to perform RMQ.
std::array< std::array< int64_t, N >, M > ST
the sparse table storing min() values for given interval.

Member Data Documentation

◆ A

std::array<int64_t, N> data_structures::sparse_table::Sparse_table::A = {}

input array to perform RMQ.

Warning
check if N is not less than n. if so, manually increase the value of N

Definition at line 57 of file sparse_table.cpp.

57{};

◆ LOG

std::array<int64_t, N> data_structures::sparse_table::Sparse_table::LOG = {}

where floor(log2(i)) are precomputed.

Definition at line 60 of file sparse_table.cpp.

60{};

◆ n

size_t data_structures::sparse_table::Sparse_table::n = 0

size of input array.

Definition at line 52 of file sparse_table.cpp.

◆ ST

std::array<std::array<int64_t, N>, M> data_structures::sparse_table::Sparse_table::ST {}

the sparse table storing min() values for given interval.

Definition at line 59 of file sparse_table.cpp.

59{};

The documentation for this struct was generated from the following file: