#range #solve #minimum

range_minimum_query

Range Minimum Query (RMQ) is used on arrays to find the position of an element with the minimum value between two specified indices

2 unstable releases

0.2.0 Oct 2, 2024
0.1.0 Sep 27, 2022

#641 in Data structures

Download history 5/week @ 2024-07-30 2/week @ 2024-09-17 15/week @ 2024-09-24 189/week @ 2024-10-01 28/week @ 2024-10-08 9/week @ 2024-10-15 2/week @ 2024-10-22

231 downloads per month

MIT license

48KB
984 lines

Range Minimum Query (RMQ) Crates.io Docs.rs MIT licensed

This crate implements a succinct data structure to solve the Range Minimum Query (RMQ) problem in constant time and linear space.

This code was derived (almost verbatim) from a succinct version of RMQ, implemented by Giuseppe Ottaviano's succinct c++ library: https://github.com/ot/succinct.

What is RMQ (taken from Wikipedia)

In computer science, a range minimum query (RMQ) solves the problem of finding the minimal value in a sub-array of an array of comparable objects. Range minimum queries have several use cases in computer science, such as the lowest common ancestor problem and the longest common prefix problem (LCP).

For example, when A = [0,5,2,5,4,3,1,6,3], then the answer to the range minimum query for the sub-array A[2...7] = [2,5,4,3,1,6] is 6, as A[6] = 1.

Usage

use range_minimum_query::Rmq;

let a = [0,5,2,5,4,3,1,6,3];
let rmq = Rmq::from_iter(a);
let res = rmq.range_minimum(2..=7);
assert_eq!(res.unwrap(),6);

License

MIT

Dependencies

~1MB
~26K SLoC