powered by
Finds the index of the bin a number belongs to.
search_bin(arr, x)
The index i such that arr[i] <= x <= arr[i+1].
i
arr[i] <= x <= arr[i+1]
A vector of size at least 2.
A number. Must be within the range of [arr[1], arr[length(arr)]].
arr[1]
arr[length(arr)]
Finds the smallest index i such that arr[i] <= x <= arr[i+1]. Calls binarySearch_bin() if length(arr) > 8 and calls naiveSearch_bin() otherwise.
binarySearch_bin()
length(arr) > 8
naiveSearch_bin()
search_bin(1:10, seq(1, 10, by=0.5))
Run the code above in your browser using DataLab