MCPcopy Create free account
hub / github.com/TheAlgorithms/JavaScript / QuickSelect

Function QuickSelect

Data-Structures/Array/QuickSelect.js:14–20  ·  view source on GitHub ↗

* [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)

Source from the content-addressed store, hash-verified

12 */
13
14function 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
22function RandomizedSelect(items, left, right, i) {
23 if (left === right) return items[left]

Callers 1

Calls 1

RandomizedSelectFunction · 0.85

Tested by

no test coverage detected