slice::select_nth_unstable
has O(n^2) complexity, docs claim O(n) worst case
#91644
Labels
A-docs
Area: Documentation for any part of the project, including the compiler, standard library, and tools
C-bug
Category: This is a bug.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
To reproduce, run the following program:
Running this program on the latest stable or nightly Rust we get output:
Multiplying the input size by 10 increases the number of comparisons by a factor of 100 - clearly quadratic.
Looking into the code, currently the implementation of
select_nth_unstable
uses pure quickselect, explaining the quadratic behavior. To get guaranteed linear time behavior there needs to be a median-of-medians fallback in case the number of iterations of quickselect becomes too large.The text was updated successfully, but these errors were encountered: