public interface QuickSelect<T extends java.lang.Comparable> extends BaseInterface<T>
Find kth largest/smallest element in an unsorted array, in Linear time as average-case.
ARRAY_IS_EMPTY, DATA_TYPE_NOT_SUPPORTED_YET, DECIMAL_RADIX, DELIMITER_COMMA, ELEMENT_NOT_FOUND, LIST_IS_EMPTY, OPERATION_NOT_SUPPORTED_YET
Modifier and Type | Method and Description |
---|---|
default T |
findKthLargest(T[] objects,
int k) |
default T |
findKthSmallest(T[] objects,
int k)
QuickSelect based default implementation for findKthSmallest problem. |
default void |
kCheck(int n,
int k) |
default int |
medianOf3(T[] a,
int s,
int e)
|
default int |
pivotSort(T[] a,
int s,
int e,
int p)
Core Algorithm to sort one side of the pivot. |
default T |
quickSelect(T[] objects,
int k,
int s,
int e)
Core QuickSelect Algorithm. |
checkArray, checkIntArray, checkList
default T findKthSmallest(T[] objects, int k)
objects
- input arrayk
- 3rd smallest = 3, when objects:[1,2,3,4,5] and k=3default T quickSelect(T[] objects, int k, int s, int e)
objects
- input arrayk
- 3rd smallest = 3, when objects:[1,2,3,4,5] and k=3s
- start index (inclusive)e
- end index (inclusive)default int pivotSort(T[] a, int s, int e, int p)
a
- input arrays
- start index (inclusive)e
- end index (inclusive)p
- initial pivotdefault int medianOf3(T[] a, int s, int e)
a
- input arrays
- start index (inclusive)e
- end index (inclusive)default void kCheck(int n, int k)