Description Usage Arguments Details Value
View source: R/BinarySearch_onListOfNumericVectors.R
This is a generic function to perform binary search of log2(n) time complexity to search a list of SORTED numeric vectors (in increasing order) and retriving their keys.
1 2 3 4 5 6 7 | binarySearch_onListOfNumericVectors(
VecToBeQueried,
lst_ofSortedVecs,
left_index = 1,
right_index = length(lst_ofSortedVecs),
verbose = F
)
|
VecToBeQueried |
Numeric vector to be queried |
lst_ofSortedVecs |
List of numeric vectors sorted by values in increasing order |
Binary search requires a sense of ordering (thus uses recursion). The order is defined by the left-most member of the numeric vector that differs between the two neighbouring vectors. For example [c(1,1,1), c(1,1,2), c(1,2,1)] is in order but [c(1,1,1), c(1,2,1), c(1,1,2)] is not (becasue the left-most number differing is 2 in the second element which should be a third element to be considered ordered). A numeric vector supersedes (comes after) another numeric vector if the left-most differeing number between the two vectors is higher in value.
A numeric key index of lst_ofSortedVecs corresponding to query. NA is returned if VecToBeQueried is not in lst_ofSortedVecs.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.