File tree 1 file changed +3
-5
lines changed
1 file changed +3
-5
lines changed Original file line number Diff line number Diff line change 2
2
* [QuickSelect](https://www.geeksforgeeks.org/quickselect-algorithm/) is an algorithm to find the kth smallest number
3
3
*
4
4
* Notes:
5
- * - QuickSelect is related to QuickSort, thus has optimal best and average case (O(n)) but unlikely poor worst case (O(n^2))
6
- * - This implementation uses randomly selected pivots for better performance
5
+ * - QuickSelect is related to QuickSort, thus has optimal best and average case O(n) but unlikely poor worst case O(n^2)
7
6
* ----
8
- * @complexity : O(n) (on average )
9
- * @complexity : O(n^2) (worst case)
7
+ * @complexity O(n) (on average)
8
+ * @complexity O(n^2) (worst case)
10
9
* ----
11
10
* @param items array
12
11
* @flow
13
12
*/
14
13
15
14
const QuickSelect = ( items : Array < number > , kth : number ) : number => {
16
- // eslint-disable-line no-unused-vars
17
15
if ( kth < 1 || kth > items . length ) {
18
16
throw new RangeError ( "Index Out of Bound" ) ;
19
17
}
You can’t perform that action at this time.
0 commit comments