# Plans for an algorithm to find Kth Order Statistic from Array?

**URL:** <https://forums.swift.org/t/plans-for-an-algorithm-to-find-kth-order-statistic-from-array/70094>\
**Category:** Algorithms\
**Created:** [February 16, 2024, 8:31pm UTC](https://forums.swift.org/t/plans-for-an-algorithm-to-find-kth-order-statistic-from-array/70094 "2024-02-16T20:31:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanvoorden](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vanvoorden/32/33619_2.png) [@vanvoorden](https://forums.swift.org/u/vanvoorden)\
**Post date:** [February 16, 2024, 8:31pm UTC](https://forums.swift.org/t/plans-for-an-algorithm-to-find-kth-order-statistic-from-array/70094/1 "2024-02-16T20:31:09Z")

</div>

Hi! I just started searching through the algorithms package and I don't (yet) see if there is an algorithm for selecting the Kth Order Statistic from a Swift Array or Set. My guess is this would also be expected to run in linear time. Is this named something else in the package? Were there plans or blockers for shipping this in the future? Thanks!

---

<div class="post-metadata">

**Author:** ![vanvoorden](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vanvoorden/32/33619_2.png) [@vanvoorden](https://forums.swift.org/u/vanvoorden)\
**Post date:** [April 15, 2025, 11:41pm UTC](https://forums.swift.org/t/plans-for-an-algorithm-to-find-kth-order-statistic-from-array/70094/2 "2025-04-15T23:41:56Z")

</div>

I still was looking for any more clues on this… I found another place I would have wanted this ability. I did find the min-max functions… but this looks like it would return the `k` smallest or largest elements _sorted_. My preference would have been to either just return the Kth Order Statistic or return the `k` elements _unsorted_.

> <https://github.com/apple/swift-algorithms/blob/main/Guides/MinMax.md>

---

<div class="post-metadata">

**Author:** ![vanvoorden](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vanvoorden/32/33619_2.png) [@vanvoorden](https://forums.swift.org/u/vanvoorden)\
**Post date:** [December 23, 2025, 11:16pm UTC](https://forums.swift.org/t/plans-for-an-algorithm-to-find-kth-order-statistic-from-array/70094/3 "2025-12-23T23:16:53Z")

</div>

I think what we are looking for would be similar to [`nth_element`](https://en.cppreference.com/w/cpp/algorithm/nth_element.html) from `<algorithm>` in C++.

Did anyone else want this? I could work on a pitch if anyone else was waiting for that.
