Answers for "recursion binary search c++"

C++
5

recursive binary search

int binarySearch(int[] A, int low, int high, int x)
{
    if (low > high) {
        return -1;
    }
    int mid = (low + high) / 2;
    if (x == A[mid]) {
        return mid;
    }
    else if (x < A[mid]) {
        return binarySearch(A, low,  mid - 1, x);
    }
    else {
        return binarySearch(A, mid + 1,  high, x);
    }
}
Posted by: Guest on January-04-2022

Code answers related to "recursion binary search c++"

Browse Popular Code Answers by Language