This is a binary search operation if the element is found, and it matches an element at an index precisely, then that index is returned.
This is a binary search operation if the element is found, and it matches an element at an index precisely, then that index is returned.
If the element is not found it will return a negative number. the index returned is as follows, if it is before the 0th index then -1 is returned if it is before the first index, but after the zeroeth then -2 is returned if it is before the second index, but after the first then -3 is returned and so on. if it is after the last index then -(size+1) is returned (as would be expected).
Here are some examples xs = [3,5,7,9] Here is a break down of the locations for each input of bs(xs, x) where x is one of: [-Inf,3) = -1 [3,3] = 0 (3,5) = -2 [5,5] = 1 (5, 7) = -3 [7,7] = 2 (7,9) = -4 [9,9] = 3 (9, Inf] = -5
When there are duplicates this will return the index of the last duplicate
Inserts an element into a sorted array and returns a new sorted array
Inserts an element into a sorted array and returns a new sorted array
type of sequence and element
new sequence with element inserted in the right spot