Skip to content

Instantly share code, notes, and snippets.

@tangingw
Created March 3, 2017 03:59
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 tangingw/1f60cdc8dda18fe4a39c03ac8d42d531 to your computer and use it in GitHub Desktop.
Save tangingw/1f60cdc8dda18fe4a39c03ac8d42d531 to your computer and use it in GitHub Desktop.
This is golang binary search in recursive form
package main
//Recursive Binary Search
func binarySearch(numList []int64, key int64) int {
low := 0
high := len(numList) - 1
if low <= high {
mid := ((high + low) / 2)
if numList[mid] > key {
return binarySearch(numList[:mid], key)
} else if numList[mid] < key {
return binarySearch(numList[mid+1:], key)
} else {
return 1
}
}
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment