Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

Binary Search in C-Recursive Method

int bSearch(int arr[], int left, int right, int target) {
    if (right >= left) {
        int mid = left + (right - left) / 2;
 
        if (arr[mid] == target)
            return mid;
 
        if (arr[mid] > target)
            return binarySearch(arr, left, mid - 1, target);
 
        return binarySearch(arr, mid + 1, right, target);
    }
    return -1;
}
Source by www.interviewbit.com #
 
PREVIOUS NEXT
Tagged: #Binary #Search #Method
ADD COMMENT
Topic
Name
3+2 =