import { default } from "https://deno.land/x/simplestatistics@v7.7.6/src/quickselect.js";
Rearrange items in arr
so that all items in [left, k]
range are the smallest.
The k
-th element will have the (k - left + 1)
-th smallest value in [left, right]
.
Implements Floyd-Rivest selection algorithm https://en.wikipedia.org/wiki/Floyd-Rivest_algorithm
Examples
var arr = [65, 28, 59, 33, 21, 56, 22, 95, 50, 12, 90, 53, 28, 77, 39];
quickselect(arr, 8);
// = [39, 28, 28, 33, 21, 12, 22, 50, 53, 56, 59, 65, 90, 77, 95]
var arr = [65, 28, 59, 33, 21, 56, 22, 95, 50, 12, 90, 53, 28, 77, 39]; quickselect(arr, 8); // = [39, 28, 28, 33, 21, 12, 22, 50, 53, 56, 59, 65, 90, 77, 95]