Skip to content

Instantly share code, notes, and snippets.

@ButlerFuqua
Created April 5, 2021 19:12
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 ButlerFuqua/873fc1001fe3cc3a0c09004c27c68ca5 to your computer and use it in GitHub Desktop.
Save ButlerFuqua/873fc1001fe3cc3a0c09004c27c68ca5 to your computer and use it in GitHub Desktop.
BinarySearch(numbers, low, high, key) {
if (low > high)
return -1
mid = (low + high) / 2
if (numbers[mid] < key) {
return BinarySearch(numbers, mid + 1, high, key)
}
else if (numbers[mid] > key) {
return BinarySearch(numbers, low, mid - 1, key)
}
return mid
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment