binary search using recursion

PHOTO EMBED

Sun Jun 30 2024 09:06:00 GMT+0000 (Coordinated Universal Time)

Saved by @vishnu_jha #c++ #dsa #recursion #array #binarysearch

bool binarySearch(int arr[], int s, int e, int key) {
  if (s > e)
    return false;
  int mid = s + (e - s) / 2;
  if (arr[mid] == key)
    return true;
  if (arr[mid] < key)
    return binarySearch(arr, mid + 1, e, key);
  else
    return binarySearch(arr, s, mid - 1, key);
}
content_copyCOPY