order-stat 0.1.0

Compute order statistics efficiently via the Floyd-Rivest algorithm and estimate a median via the median-of-medians algorithm.
Documentation

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);