Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created March 20, 2021 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/265d0b6f5f6b4f267770724bfb3d88ba to your computer and use it in GitHub Desktop.
Save amankharwal/265d0b6f5f6b4f267770724bfb3d88ba to your computer and use it in GitHub Desktop.
def rec_binarySearch(target, sequence, first, last):
if first > last:
return False
else:
mid = (last + first) // 2
if sequence[mid] == target:
return True
elif target < sequence[mid]:
return rec_binarySearch(target, sequence, first, mid-1)
else:
return rec_binarySearch(target, sequence, mid + 1, last)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment