* [QuickSelect](https://www.geeksforgeeks.org/quickselect-algorithm/) is an algorithm to find the kth smallest number * * Notes: * -QuickSelect is related to QuickSort, thus has optimal best and average * -case (O(n)) but unlikely poor worst case (O(n^2)) * -This implementation uses randomly se
(items, kth)
| 12 | */ |
| 13 | |
| 14 | function QuickSelect(items, kth) { |
| 15 | if (kth < 1 || kth > items.length) { |
| 16 | throw new RangeError('Index Out of Bound') |
| 17 | } |
| 18 | |
| 19 | return RandomizedSelect(items, 0, items.length - 1, kth) |
| 20 | } |
| 21 | |
| 22 | function RandomizedSelect(items, left, right, i) { |
| 23 | if (left === right) return items[left] |
no test coverage detected