Crate order_stat [] [src]

Calculate order statistics.

This crates allows one to compute the kth smallest element in (expected) linear time, and estimate a median element via the median-of-medians algorithm.

Source

Installation

Ensure your Cargo.toml contains:

[dependencies]
order-stat = "0.1"

Examples

let mut v = [4, 1, 3, 2, 0];

println!("the 2nd smallest element is {}", order_stat::kth(&mut v, 1));
let mut v = [4, 1, 3, 2, 0];

println!("{} is close to the median", order_stat::median_of_medians(&mut v).1);

Functions

kth

Compute the kth order statistic (kth smallest element) of array via the Floyd-Rivest Algorithm[1].

median_of_medians

Calculate an approximate median of array.