TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation of Sparse Table for min()
function.
More...
#include <array>
#include <cassert>
#include <cstdint>
#include <iostream>
Go to the source code of this file.
Classes | |
struct | data_structures::sparse_table::Sparse_table |
Namespaces | |
namespace | data_structures |
for IO operations | |
namespace | sparse_table |
Functions for Implementation of Sparse Table | |
Functions | |
static void | test () |
Self-test implementations. | |
int | main (int argc, char *argv[]) |
Main function. | |
Variables | |
constexpr uint32_t | data_structures::sparse_table::N = 12345 |
A struct to represent sparse table for min() as their invariant function, for the given array A . The answer to queries are stored in the array ST. | |
constexpr uint8_t | data_structures::sparse_table::M = 14 |
ceil(log2(N)). | |
Implementation of Sparse Table for min()
function.
Implementation of Sparse Table data structure.
Sparse Table is a data structure, that allows answering range queries. It can answer most range queries in O(logn), but its true power is answering range minimum queries (or equivalent range maximum queries). For those queries it can compute the answer in O(1) time. The only drawback of this data structure is, that it can only be used on immutable arrays. This means, that the array cannot be changed between two queries.
If any element in the array changes, the complete data structure has to be recomputed.
min(a1,a2,...an)
duplicate invariant function. This implementation can be changed to other functions like gcd()
, lcm()
, and max()
by changing a few lines of code.Sparse Table is a data structure, that allows answering range queries. It can answer most range queries in O(logn), but its true power is answering range minimum queries or equivalent range maximum queries). For those queries it can compute the answer in O(1) time.
Definition in file sparse_table.cpp.
int main | ( | int | argc, |
char * | argv[] ) |
Main function.
argc | commandline argument count (ignored) |
argv | commandline array of arguments (ignored) |
Definition at line 162 of file sparse_table.cpp.
|
static |
Self-test implementations.
< array on which RMQ will be performed.
< size of self test's array
< declaring sparse tree
< copying array to the struct
< passing the array's size to the struct
< precomputing sparse tree
< as 1 is smallest from 1..9
< as 2 is smallest from 2..6
< as 3 is smallest from 3..8
Definition at line 129 of file sparse_table.cpp.
|
constexpr |
ceil(log2(N)).
Definition at line 49 of file sparse_table.cpp.
|
constexpr |
A struct to represent sparse table for min()
as their invariant function, for the given array A
. The answer to queries are stored in the array ST.
the maximum size of the array.
Definition at line 48 of file sparse_table.cpp.