Fact-checked by Grok 2 weeks ago

Introselect

Introselect is a hybrid selection algorithm designed to find the k-th smallest element in an unordered list, combining the average-case efficiency of quickselect with the worst-case linear time guarantees of algorithms like median-of-medians, ensuring O(n) time complexity overall while maintaining practical performance for typical inputs. Developed as the selection counterpart to the introsort algorithm, introselect addresses the limitations of quickselect, which achieves O(n) average time but can degrade to O(n2) in the worst case due to unbalanced partitions from poor pivot choices. It operates by initially applying quickselect's partitioning strategy, which recursively divides the list around a pivot to isolate the target element, but monitors the recursion depth to prevent excessive imbalance. If the depth exceeds a threshold—typically around 2 log2(n)—it switches to a guaranteed linear-time selection method, such as median-of-medians, for the remaining subproblem, thereby bounding the total work to O(n). Introselect was introduced by David R. Musser in his 1997 paper "Introspective Sorting and Selection Algorithms," presented at the Ninth Annual ACM-SIAM Symposium on Discrete Algorithms, where it was proposed alongside to provide robust, in-place selection with introspective depth limiting. This approach draws inspiration from quicksort's partitioning but incorporates safeguards inspired by earlier linear-time selection work, such as the Blum-Floyd-Pratt-Rivest-Tarjan algorithm from 1973. Due to its balance of speed and reliability, introselect has been widely adopted in standard libraries; for instance, it forms the basis of the library's std::nth_element function, which rearranges elements to place the k-th in its sorted position without fully sorting the array. Implementations often optimize further by using for small subarrays and median-of-three pivots to enhance average-case behavior.

Overview

Definition and Purpose

Introselect is a hybrid deterministic selection algorithm designed to find the k-th smallest element (the k-th ) in an unordered list of n elements, where 1 ≤ kn. It achieves this by partitioning the such that the k-th smallest element occupies its final sorted position, with all elements smaller than it preceding it and all larger elements following it. This process ensures the selected element is correctly placed without fully the , making it efficient for tasks like partial sorting or computation. The primary purpose of introselect is to combine the average-case linear time performance of quickselect with the worst-case linear time guarantee of more robust methods, thereby addressing quickselect's vulnerability to quadratic performance in pathological cases. , based on Hoare's find algorithm, typically runs in O(n) time on average but can degrade to O(n2) in the worst case due to poor pivot choices. To mitigate this, introselect incorporates a fallback mechanism inspired by the median-of-medians algorithm (BFPRT), ensuring reliable linear-time execution even under adversarial inputs. This hybrid approach was proposed to enhance the dependability of selection routines in practical implementations, such as those used in standard libraries for reliable partial sorting and queries.

Key Properties

Introselect is a hybrid that integrates the partitioning mechanism of with a guaranteed linear-time fallback strategy, such as the Blum-Floyd-Pratt-Rivest-Tarjan (BFPRT) algorithm, to achieve both practical efficiency and theoretical worst-case guarantees. This combination allows introselect to leverage 's simple, in-place partitioning for most cases while invoking the more robust BFPRT only when necessary to prevent pathological performance degradation. The algorithm ensures a worst-case time complexity of O(n) by employing depth-limited recursion, where the partitioning phase is restricted to avoid excessive recursion depth that could lead to quadratic behavior. In the average case, introselect performs comparably to quickselect, approaching O(n) time due to its initial reliance on optimistic partitioning with heuristics like median-of-three pivot selection. It operates in-place, modifying the input array directly without allocating additional space proportional to the input size n, thus requiring only O(log n) auxiliary stack space for recursion. Introselect exhibits deterministic behavior, eschewing randomization in favor of fixed pivot selection strategies and recursion depth controls to ensure predictable outcomes across inputs. The switching threshold is typically set to limit recursion depth to approximately k \lceil \log n \rceil levels, where k is a small positive (often 2), after which the algorithm falls back to the linear-time selector to maintain the O(n) bound.

History

Development by David Musser

David Musser, a of at , invented introselect as an advancement in selection algorithms. His extensive contributions to , including collaboration with on the development of the (STL), shaped the algorithm's emphasis on adaptable, template-based implementations suitable for C++ environments. In 1997, Musser developed introselect amid ongoing efforts to establish robust, standardized algorithms for the emerging , particularly to support reliable partial sorting operations in the STL. The primary was to mitigate the worst-case O(n²) of , which posed risks in production code due to potential degenerate inputs, by incorporating a hybrid strategy that bounded depth while preserving average-case efficiency. This innovation drew direct inspiration from Musser's concurrent work on , a hybrid sorting algorithm that switches to in worst-case scenarios to guarantee O(n log n) performance; introselect applies a similar mechanism to selection tasks. Musser first proposed introselect in his seminal paper "Introspective Sorting and Selection Algorithms," published in Software: Practice and Experience 27(8): 983–993 (August 1997).

Evolution and Publications

The primary publication on introselect appeared in 1997 as part of David R. Musser's paper "Introspective Sorting and Selection Algorithms," published in Software: Practice and Experience 27(8): 983–993 (August 1997), where he detailed the algorithm's hybrid structure combining with median-of-medians for linear worst-case , alongside experimental results demonstrating its efficiency on various input distributions. In this work, Musser promised further extensions, including a dedicated paper on comprehensive experimental comparisons with other selection algorithms and explorations of alternative partitioning methods beyond median-of-3, but no such follow-up materialized. Introselect's influence extended to standardization shortly thereafter, with its adoption in the C++98 for the std::nth_element function, which rearranges elements to position the nth smallest without full sorting; however, the standard specifies only average-case linear time, permitting implementations that deviate from strict O(n) worst-case guarantees, though many, like those in libstdc++, employ introselect to achieve it. Musser retired in 2007 from , after which no major updates or seminal publications on the algorithm emerged from him, contributing to its relative stasis in core design. As of 2025, academic and open-source continue to reference introselect for practical selection tasks, with refinements primarily targeting selection strategies to enhance average-case on modern , such as in GPU-accelerated contexts or sparse data scenarios, while the fundamental hybrid mechanism remains unaltered. For instance, recent repositories explore optimized pivot choices and partitioning schemes tailored to specific use cases like recommendation systems. Coverage of potential variants, including heap-based fallbacks for selection, remains limited in the , with discussions often confined to implementation notes rather than formal analyses.

Algorithm Description

Core Components

Introselect integrates the algorithm as its primary mechanism for finding the k-th smallest element in an unsorted , employing to divide the around a chosen and recursively applying the process to the relevant subarray containing the target position. This approach leverages quickselect's expected linear-time performance under random or well-chosen pivots, focusing on only one subarray after each to maintain efficiency. Pivot selection in introselect typically uses heuristics such as the median-of-three method, which evaluates the first, middle, and last elements of the current subarray to choose a that approximates the and promotes balanced partitions on average, reducing the likelihood of skewed . Alternative heuristics, like the median of nine elements, may be employed in some variants to further improve pivot quality without significant overhead. The tracks recursion depth by maintaining a for the number of nested calls, initialized based on the array size to ensure the process aligns with quickselect's expected logarithmic depth under balanced partitioning. This monitoring starts with the assumption of quickselect's linear expected time, incrementing the depth with each step on the selected subarray. A fallback trigger activates when the recursion depth exceeds a predefined , commonly set to $2 \log_2 n where n is the initial array size, indicating potential degradation into worst-case quadratic behavior due to poor pivots. At this point, introselect switches to a guaranteed linear-time selection method, such as , to ensure overall worst-case performance. In practical implementations, such as the C++ standard library's std::nth_element, a simpler O(n log n) fallback like heapselect is often used instead due to better constant factors. The partitioning step follows pivot selection by rearranging the subarray such that all elements less than or equal to the are moved to the left, all greater elements to the right, and the is placed in its final sorted position, typically using schemes like Hoare or Lomuto partitioning for in-place operation. Hoare partitioning, in particular, scans from both ends toward the center, swapping elements as needed to achieve the division efficiently in linear time relative to the subarray size.

Hybrid Switching Mechanism

The hybrid switching mechanism in introselect addresses the worst-case quadratic behavior of by dynamically monitoring progress and falling back to a guaranteed linear-time algorithm when necessary. , which relies on partitioning the array around a and recursing on the relevant subarray containing the k-th element, is used as the primary method due to its linear average-case performance. However, to prevent deep on unbalanced partitions that fail to sufficiently reduce the problem size, introselect tracks the depth along the path to the target element. The depth limit is set to approximately $2 \log_2 n, where n is the initial array size, ensuring that the total work before switching remains bounded and contributes at most O(n \log n) in the worst case, while the fallback guarantees overall linear time. The original proposal monitors progress more precisely by checking if the subarray size is reduced by at least half; if not for k consecutive partitions (with k typically 2), it signals insufficient progress and may trigger the switch earlier. Common implementations simplify this to a straightforward . The switch condition triggers when the counter reaches the depth limit, at which point introselect invokes the median-of-medians algorithm (also known as BFPRT) on the current subarray to select a high-quality that guarantees at least a constant fraction reduction in size, ensuring linear progress thereafter. The fallback is applied only along the path leading to the k-th element, avoiding unnecessary overhead on discarded portions. Some variants of introselect optimize this mechanism by using a total work estimation instead of a pure depth , tracking the cumulative cost of (e.g., the sum of subarray sizes processed) to detect stagnation earlier and switch proactively. This approach, informed by on quality, maintains the same asymptotic guarantees while adapting better to input distributions in .

Pseudocode Outline

The introselect algorithm operates by iteratively the array using a quickselect-inspired approach, with a depth to prevent excessive depth, and falls back to a linear-time selection method when necessary. The following high-level illustrates a simplified common implementation, adapted from descriptions in the , where the selection typically employs a median-of-three and the step rearranges elements around the such that elements less than the precede it and greater elements follow, akin to the function in . (Note: This uses a simple depth ; the original paper includes checks for consecutive insufficient size reductions.)
pseudocode
function introselect(array A, int k, int left, int right, int depth_limit):
    depth = 0
    while left < right:
        if right - left <= 1:
            return A[k]
        if depth > depth_limit:
            return median_of_medians_select(A, k, left, right)
        pivot_index = select_pivot(A, left, right)  // e.g., median of three
        pivot_index = partition(A, left, right, pivot_index)
        if pivot_index == k:
            return A[k]
        elif pivot_index > k:
            right = pivot_index
        else:
            k = k - (pivot_index - left + 1)
            left = pivot_index + 1
        depth += 1
    return A[k]
To invoke introselect on an A of size n to find the k-th smallest (0-indexed), initialize the call as introselect(A, [k](/page/K), 0, n-1, 2 * floor(log_2(n))), where the depth limit ensures the depth remains bounded by O(\log n) in the worst case before invoking the fallback. The median_of_medians_select implements the linear-time (e.g., BFPRT) to guarantee O(n) worst-case performance when the phase risks quadratic behavior. Termination occurs when the subarray size is at most 1 or the lands exactly at position k, at which point the k-th is returned.

Implementations

In C++ Standard Library

Introselect forms the foundational algorithm for std::nth_element in the C++ Standard Library, which was standardized in C++98 and included in the <algorithm> header to provide a partial sorting operation that rearranges elements such that the nth element is in its sorted position, with elements before it not exceeding it and elements after it not smaller. This implementation stems from David Musser's original proposal for a template-based generic selection algorithm, detailed in his 1997 paper introducing introselect as a hybrid approach suitable for the emerging C++ Standard Template Library. The C++ standard requires std::nth_element to achieve O(n) average-case complexity in comparisons and applications of the comparison function, but it imposes no worst-case linear time guarantee, allowing implementations flexibility for optimization; typically, these use quickselect as the primary method with a heapselect fallback to mitigate poor pivot choices. Compiler-specific variations enhance reliability, as seen in GCC's libstdc++ where recursion depth is capped (often at 2 log n levels) to prevent stack overflow, switching to a heapsort-based selection for deeper subproblems and yielding O(n log n) worst-case performance. As of the C++23 standard, finalized in 2023, these specifications remain unchanged, preserving the average-case focus to prioritize practical efficiency over strict worst-case bounds.

In GNU C Library (glibc)

The GNU C Library (glibc), starting from version 2.0 released in 1998, does not provide a public function named qselect or a dedicated implementation of introselect for generic selection in C/POSIX environments. Instead, the library focuses on standard functions like qsort for full array sorting, with early versions (up to glibc 2.2) employing a quicksort variant that used median-of-three pivot selection to improve average-case performance on random data. This approach helped mitigate poor pivot choices but did not incorporate the introspective depth-limiting mechanism of introselect, which switches to median-of-medians for guaranteed O(n) worst-case time when recursion depth exceeds a threshold like 2 log n. From 2.3 in the early 2000s through version 2.38, was reimplemented as a mergesort-based to ensure consistent O(n log n) worst-case performance and stability, addressing vulnerabilities to denial-of-service attacks that could degrade to time. Minor optimizations were introduced in subsequent releases, such as improved memory allocation handling and indirect for large elements. However, starting with 2.39 (released February 2024), was switched to an introsort-based implementation—a hybrid with recursion depth limiting and fallback to —to improve average-case speed while maintaining stability against attacks. This core strategy remains in place as of 2025. This is widely used in tools like those in Coreutils for tasks requiring sorted output, though it performs full rather than partial selection. For partial sorting or k-th element selection needs in pure C code, developers must provide custom implementations, often adapting with enhancements like median-of-three pivots for practicality. Relatedly, the (libstdc++, built atop ) employs in its std::nth_element function to offer efficient selection with both fast average and linear worst-case behavior.

Other Language Adaptations

In , the Numbers library implements a class that employs an introselect variant with dual-pivot partitioning for efficient selection tasks. This adaptation draws from the original introsort principles to ensure average-case performance while mitigating worst-case scenarios through hybrid switching. Python's standard library does not include a pure introselect implementation; instead, functions like heapq.nlargest and heapq.nsmallest rely on heap-based selection, while sorted uses Timsort for full sorting. However, third-party libraries provide introselect adaptations, such as custom implementations for order statistics computation. NumPy's partition function, widely used in data science, incorporates an introselect algorithm with worst-case linear time complexity for partial sorting and k-selection. Rust's standard library includes introselect in the slice module's select_nth_unstable method, introduced since version 1.0 in 2015, which hybridizes quickselect with a median-of-medians fallback using Tukey's ninther for pivot selection to guarantee O(n) worst-case performance. This ensures robust nth-element selection without quadratic degradation. In Go, the standard sort package primarily uses quickselect without full hybrid introspection, but community packages like github.com/yannickperrenet/introselect offer complete introselect implementations that limit recursion depth and switch to median-of-medians for O(n) guarantees. As of 2025, introselect adaptations are increasingly integrated into data science libraries beyond NumPy, such as in enhanced partial sort functions for efficient k-selection in large datasets.

Performance Analysis

Time Complexity

Introselect achieves an average-case time complexity of O(n), primarily because it relies on quickselect for most executions, where balanced partitions occur with probability greater than $1/4, leading to expected linear time overall. In the worst case, introselect also runs in O(n) time by incorporating a median-of-medians fallback mechanism, which guarantees at least a 30% reduction in problem size per recursive level. The algorithm monitors partitioning progress and switches to the fallback if the subproblem size does not reduce sufficiently (such as failing to at least halve over a small number of consecutive steps), combined with a depth limit, ensuring the total work remains linear. The depth limit is set to approximately $2 \log_2 n, but the switching condition bounds the computational effort to at most c n for some constant c > 0. Note that some practical implementations use a simpler depth limit with heapselect fallback, resulting in O(n \log n) worst-case time. The cost of each partition is O(n), while the median-of-medians fallback solves the recurrence T(n) \leq T(n/5) + T(7n/10) + O(n), which resolves to O(n) via the or substitution method. In practice, the fallback mechanism rarely triggers, resulting in runtimes that closely match those of plain .

Space Complexity and Practical Considerations

Introselect operates as an in-place , requiring no auxiliary arrays or data structures proportional to the input size beyond the original array. Its arises primarily from the stack, which is bounded at O(log n) in the worst case due to the depth limit enforced by the switching to prevent excessive . This limit ensures that the algorithm avoids deep call stacks while maintaining the linear time guarantee. To further optimize memory usage, many implementations of introselect incorporate tail elimination, converting the recursive partitioning into an iterative process that recurses only on the relevant subarray. This technique reduces the auxiliary to O(1), as the frames are reused rather than accumulated, making it highly efficient for large inputs on systems with limited space. In practice, the median-of-medians fallback introduces notable overhead, as its selection process is approximately 3-5 times slower than quickselect's partitioning due to the additional recursive computations across groups. To balance this, implementations conservatively tune the recursion depth limit—often to around 2 log₂ n—to rarely invoke the fallback, preserving quickselect-like speed in average cases. The partitioning steps themselves exhibit strong friendliness, akin to , by sequentially accessing array elements during swaps, which enhances locality on modern processors; however, the fallback's calculations can incur misses from non-contiguous groupings.

Comparisons

With Quickselect

is a that uses recursive partitioning, akin to , to locate the k-th smallest element in an unordered list. It selects a , partitions the list into sublists of elements smaller and larger than the , and recurses only on the sublist containing the target element. This approach yields an average-case of O(n), making it efficient for typical inputs, but it suffers from a worst-case time complexity of O(n²), especially on presorted or nearly sorted data where consistent poor pivot selection results in highly unbalanced partitions. Introselect addresses quickselect's vulnerability by incorporating a recursion depth limit, usually set to approximately 2 log₂ n levels, beyond which it switches to a guaranteed linear-time selection method. This hybrid switching mechanism ensures a worst-case time complexity of O(n) for introselect, comparable to quickselect's average performance, while preventing degeneration on adversarial inputs without altering the core partitioning strategy. The primary trade-off in introselect arises from the added recursion depth checks, which introduce minimal computational overhead compared to plain . However, this small cost effectively mitigates the risk of quadratic behavior on problematic datasets, such as sorted arrays, providing greater reliability in practice. Empirical evaluations confirm that introselect maintains near-equivalent average-case speed to across random inputs. Introselect is recommended for production systems handling potentially malicious or non-random inputs, where robustness against worst-case scenarios is essential. Plain remains viable for applications with assured random data distributions, avoiding the minor introspection overhead where performance predictability is already high.

With Median of Medians

The algorithm, also known as the BFPRT algorithm, guarantees worst-case linear time selection by recursively finding a good through the median of small group medians, ensuring that at least 30% of elements are eliminated in each step. However, this approach incurs high constant factors due to the recursive overhead, making it significantly slower in practice—typically 3 to 5 times slower than on large arrays, as shown in empirical benchmarks on datasets up to 90 million elements. Introselect improves upon this by employing solely as a fallback when quickselect's partitioning depth exceeds a , such as k \lceil \log_2 n \rceil, thereby inheriting the worst-case guarantee while delivering average-case performance comparable to . This hybrid strategy minimizes invocations of the more expensive median of medians routine, often avoiding it entirely in favorable inputs, which results in introselect outperforming pure median of medians by factors of 4 to 5 in timed comparisons on random and adversarial data. Both algorithms share the same underlying recurrence for the fallback phase: T(n) \leq T\left(\frac{n}{5}\right) + T\left(\frac{7n}{10}\right) + O(n) which solves to O(n) via the or substitution, but introselect rarely reaches this depth, preserving low constants in typical executions. In theoretical contexts requiring strict worst-case bounds without randomization, serves as a foundational deterministic ; conversely, introselect suits practical implementations needing a balance of guaranteed linearity and high average-case speed, as adopted in standard libraries like those in C++.

With Heapselect

Heapselect is a that constructs a from the input array in time, followed by up to k extract operations to isolate the k-th element, each requiring O(log n) time and yielding a of O(n log n). This approach provides by preserving the relative order of equal elements in certain implementations, particularly when selecting top-k elements via a of limited size. Introselect surpasses heapselect in worst-case performance by guaranteeing O(n) time through a hybrid of quickselect and median-of-medians as a fallback, avoiding heapselect's O(n log n) bound and the upfront cost of full heap construction, which can be inefficient for large k. For large k, introselect's average-case efficiency—akin to quickselect—delivers faster execution without risking quadratic degradation. Heapselect excels for small k, where its O(n + k log n) cost approximates O(n), or in scenarios prioritizing stability over strict linear worst-case guarantees. Some C++ Standard Library implementations employ heapselect as an alternative fallback in introselect variants, opting for its simpler mechanics over median-of-medians to enhance practical speed despite forgoing O(n) assurance. Introselect can integrate heapselect in hybrid configurations for added practicality, balancing empirical efficiency with controlled recursion depth at the expense of theoretical worst-case optimality.

Applications

Role in Algorithms

Introselect supports partial scenarios, such as in the library's std::partial_sort, which uses std::nth_element powered by introselect to such that the k-th smallest is in place and smaller precede it. This allows of the top-k or bottom-k by first and then only the relevant prefix, avoiding full array . The library's std::nth_element employs introselect for its average O(n) time complexity.

Use in Selection Tasks

Introselect serves as a core algorithm for finding, where the task is to identify the k-th smallest element with k = n/2 in an unsorted of n elements, enabling efficient of central tendencies in statistical . This application leverages introselect's hybrid approach, starting with for average-case speed and falling back to median-of-medians for guaranteed linear-time worst-case performance, making it suitable for large datasets where exact medians are required without full . In quantile estimation, introselect underpins functions in tools for computing , such as the 25th, 50th, and 75th used in box plots and . For instance, NumPy's partition function, which powers quantile and percentile for efficient k-selection without the entire , defaults to the introselect to balance speed and reliability across array sizes. A notable application of introselect appears in beam search pruning within AI and workflows, where maintaining the top-k scoring candidates requires repeated selection to discard lower-ranked paths efficiently. In implementations such as those described for bioinformatics tasks, introselect tracks and prunes the by selecting the k-th largest score, providing O(n) worst-case guarantees that outperform naive heaps for dynamic rescoring.

References

  1. [1]
    Introspective Sorting and Selection Algorithms - Semantic Scholar
    This paper describes a simple solution to this dilemma: limit the depth of partitioning, and for subproblems that exceed the limit switch to another ...Missing: Introselect original
  2. [2]
    [PDF] Introspective Sorting and Selection Algorithms
    The details of such \introselect" algorithms and the results of experiments comparing them with other selection algorithms will be given in a separate paper.
  3. [3]
    David R. Musser - Computer Science
    Jun 16, 2017 · Dave Musser, Professor of Computer Science, retired in 2007 after a 37-year career combining academic, industry, and research-institute ...
  4. [4]
    Generic Programming
    David R. Musser. Last updated: May 19, 2003. My working definition of generic programming is "programming with concepts," where a concept is ... Currently the most thorough development and exposition of the STL ...
  5. [5]
    yannickperrenet/introselect: Selection algorithm with O(n ... - GitHub
    To improve the runtime of quickselect, Musser proposed introselect which uses the same tactic as introsort, i.e. limiting the stack depth. The depth can be ...
  6. [6]
    How is nth_element Implemented? - c++ - Stack Overflow
    Mar 19, 2015 · As you stated introselect is a combination of quickselect and median of medians. Quickselect is very fast in average and best case but has a ...How the worst time complexity of introselect become `O(n)`?Fastest method of getting k smallest numbers in unsorted list?More results from stackoverflow.com
  7. [7]
    [PDF] Fast Deterministic Selection - Andrei Alexandrescu
    Musser's Introselect algorithm [25] proceeds with a heuristics-informed Quickselect that monitors its own performance and only switches to MedianOfMedians ...
  8. [8]
    35968 – nth_element fails to meet its complexity requirements
    Jun 19, 2020 · Worth noting, perhaps, that the C++ standard does _not_ require O(n) worst-case behavior for nth_element. The exact wording (C++11 section 25.4.Missing: introselect | Show results with:introselect<|control11|><|separator|>
  9. [9]
    qsort.c - Glibc source code glibc-2.0.4 - Bootlin Elixir Cross Referencer
    Chose the pivot element using a median-of-three decision tree. This reduces the probability of selecting a bad pivot value and eliminates certain extraneous ...
  10. [10]
  11. [11]
    SelectionPerformance xref
    ... Introselect implementation with dual-pivot partitioning. */ 129 private static final String IDP = "IDP"; 130 131 // Single k selection using various methods ...
  12. [12]
    heapq — Heap queue algorithm — Python 3.14.0 documentation
    This module provides an implementation of the heap queue algorithm, also known as the priority queue algorithm. Min-heaps are binary trees for which every ...
  13. [13]
    Order Statistics Computation - Hampus Wessman
    Jan 23, 2022 · NumPy has an implementation of introselect with worst-case linear performance as part of numpy.partition(). This is almost as easy to use in ...
  14. [14]
    numpy.partition — NumPy v2.3 Manual
    Creates a copy of the array and partially sorts it in such a way that the value of the element in k-th position is in the position it would be in a sorted array ...
  15. [15]
    Implement cupy.partition · Issue #162 - GitHub
    Jun 18, 2017 · Radixselect. numpy.partition uses introselect, which is a hybrid algorithm of quickselect and median of medians and does not paralellize well.
  16. [16]
    core/slice/sort/ select.rs
    The fallback algorithm used for introselect is Median of Medians using Tukey's Ninther 6//! for pivot selection. Using this as a fallback ensures O(n) worst ...Missing: select_nth | Show results with:select_nth
  17. [17]
    select_nth_unstable has quadratic worst-case time complexity; docs ...
    Sep 28, 2022 · To uphold the linear worst-case guarantee, select_nth_unstable would need to use Median of medians. Introselect is the hybrid version, and Fast ...
  18. [18]
    [PDF] Time Bounds for Selection* - People | MIT CSAIL
    Time Bounds for Selection*. MANUEL BLUM, ROBERT W. FLOYD, VAUGHAN PRATT,. RONALD L. RIVEST, AND ROBERT E. TARJAN. Department of Computer Science, Stanford ...
  19. [19]
    My Favorite Algorithm: Linear Time Median Finding - Russell Cohen
    Jan 15, 2018 · The C++ standard library uses an algorithm called introselect which utilizes a combination of heapselect and quickselect and has an O(nlogn) ...
  20. [20]
    (PDF) Performance Analysis of Sorting and Searching Algorithms
    Aug 28, 2025 · ... introselect. (a hybrid of quicksort and median of medians), or ... 2024. Performance analysis of sorting and searching algorithms. Aug 2025 ...<|separator|>
  21. [21]
    Algorithm 65: find | Communications of the ACM
    Algorithm 65: find. Author: C. A. R. Hoare. C. A. R. Hoare. Elliott Brothers ... Communications of the ACM, Volume 4, Issue 7. Pages 321 - 322. https://doi ...
  22. [22]
    [PDF] Randomized Algorithms - Stanford University
    Can we get the best of both worlds? Page 42. Introspective Selection. ○ The introselect algorithm intelligently combines median-of-medians and quickselect ...
  23. [23]
    Top K Elements: Mastering Heap and Quickselect Algorithms
    Stability · Heap: Stable (maintains order for equal elements) · Quickselect: Not stable (may change the order of equal elements).
  24. [24]
    libc++ std::nth_element is quadratic, should be linear #52747 - GitHub
    Dec 16, 2021 · And as I said, we already are standard compliant. Unlike std::sort, std::nth_element is required to be linear on average. orlp ...
  25. [25]
    How to find the kth largest element in an unsorted array of length n ...
    Oct 30, 2008 · ... algorithm (called introselect) taking O(n) worst case time. ... As mentioned in original paper: Dividing the list by 5 assures a ...
  26. [26]
  27. [27]
    Efficient Verified Implementation of Introsort and Pdqsort - PMC - NIH
    The introsort algorithm by Musser [28] is a generic unstable sorting algorithm that combines the good average-case runtime of quicksort [18] with the optimal O ...
  28. [28]
    Is it possible to implement median of medians introselect with no ...
    Jun 23, 2016 · Research has led me to believe that for the best worst-case time complexity, introselect is the fastest way to find a median in a set of ...If the median of medians algorithm doesn't change the avg-case ...Quick select with random pick index or with median of medians?More results from stackoverflow.comMissing: overhead | Show results with:overhead
  29. [29]
    Introselect algorithm - UV <-> Bio
    Mar 24, 2021 · When implementing a beam search, one must track the top K elements to prune the beam. One algorithm for this is Introselect, implemented in the ...
  30. [30]
    Cybersecurity Anomaly Detection in Adversarial Environments - arXiv
    May 14, 2021 · This work examines the feasibility of cost-effective unsupervised learning and graph-based methods for anomaly detection in the network intrusion detection ...