Created
September 15, 2017 21:10
-
-
Save rajatsharma/334d16dda8bdbac74bcc3d3b63b18e3a to your computer and use it in GitHub Desktop.
Binary Search in Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bsearch _ [] = "Not Found" | |
bsearch e xs | |
| e < mid xs = bsearch e (take (mid xs - 1) xs) | |
| e > mid xs = bsearch e (drop (mid xs + 1) xs) | |
| otherwise = mid xs | |
where | |
mid ls = (length ls `div` 2) :: Int |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment