src/com/michaelho/DivideAndConquer/DC2.java
/**
     * Quick select algorithm helps find the kth largest element in the unsorted array.
     * Runtime: O(N)
     *
     * @param array The array to be queried.
     * @param left The starting index.
     * @param right The ending index.
     * @param k The k for finding the kth largest element.
     *
     * @return The kth largest element in the array.
     * */
Quick select algorithm helps find the kth largest element in the unsorted array.

@param array The array to be queried.
@param left The starting index.
@param right The ending index.
@param k The k for finding the kth largest element.

@return The kth largest element in the array.
Quick select algorithm helps find the kth largest element in the unsorted array . @param array The array to be queried . @param left The starting index . @param right The ending index . @param k The k for finding the kth largest element . @return The kth largest element in the array .
int kthLargest(int[] array, int left, int right, int k) {
        if (k > 0 && k <= right - left + 1) {
            int pivot = partition(array, left, right);
            if (right - pivot == k - 1)
                return array[pivot];
            if (right - pivot > k - 1)
                return kthLargest(array, pivot + 1, right, k);
            return kthLargest(array, left, pivot - 1, k - right + pivot - 1);
        }
        return Integer.MAX_VALUE;
    }
int kthLargest ( int [ ] array , int left , int right , int k ) { if ( k > 0 && k <= right - left + 1 ) { int pivot = partition ( array , left , right ) ; if ( right - pivot == k - 1 ) return array [ pivot ] ; if ( right - pivot > k - 1 ) return kthLargest ( array , pivot + 1 , right , k ) ; return kthLargest ( array , left , pivot - 1 , k - right + pivot - 1 ) ; } return Integer . MAX_VALUE ; }
Quick select algorithm helps find the kth largest element in the unsorted array.
Quick select algorithm helps find the kth largest element in the unsorted array .