binary_search
Recursive Binary Search in Gleam, implementation with O(log N) complexity.
gleam add binary_search
import binary_search
pub fn main() {
binary_search.perform([1, 2, 6, 8, 10], 6) // => 2
binary_search.perform([1, 2, 3, 4, 5], 1) // => 0
binary_search.perform([], 6) // => -1 # indicating not found.
binary_search.perform([1, 2, 6, 8, 10], 7) // => -1
}
Further documentation can be found at https://hexdocs.pm/binary_search.
Development
gleam test # Run the tests
gleam shell # Run an Erlang shell