Package Exports
- binary-search-variations
- binary-search-variations/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (binary-search-variations) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
binary-search-variations
An npm package with several variations of Binary Search
Installation
npm i binary-search-variations
Usage
import { findGreatestLess } from 'binary-search-variations'
export default function Home() {
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
const target = 5
const result = findGreatestLess(arr, target)
console.log(result) // 4
return (
<div>
</div>
)
}
The functionalities included in this package - a. Normal Binary Search(normalBinarySearch): This is the normal binary search algorithm which returns the index of the element if found, else returns -1.
b. Find Lower Bound(findLowerBound): This function returns the index of the first element which is greater than or equal to the given element. If no such element is found, it returns -1.
c. Find Upper Bound(findUpperBound): This function returns the index of the first element which is greater than the given element. If no such element is found, it returns -1.
d. Find Least Greater(findLeastGreater): This function returns the index of the least element which is greater than the given element. If no such element is found, it returns -1.
e. Find Greatest Lesser(findGreatestLesser): This function returns the index of the greatest element which is lesser than the given element. If no such element is found, it returns -1.