recursive-binarysearch

1.0.0 • Public • Published

NPM version Build Status Dependency Status

Recursive Binary Search

A recursive Binary Search implementation with O(log N) complexity based on javascript-algorithms.

A straightforward implementation of binary search is recursive. The initial call uses the indices of the entire array to be searched. The procedure then calculates an index midway between the two indices, determines which of the two subarrays to search, and then does a recursive call to search that subarray.

Install

$ npm install --save recursive-binarysearch

Usage

var binarysearch = require('recursive-binarysearch');
 
binarySearch([1, 2, 3, 4, 6, 8], 1);
// => 0
 
binarySearch([1, 2, 3, 4, 6, 8], 4);
// => 3
 
binarySearch([1, 8], 1);
// => 0
 
binarySearch([1, 2, 3], 4);
// => -1
 
binarySearch([], 4);
// => -1

License

MIT © Addy Osmani

Package Sidebar

Install

npm i recursive-binarysearch

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • addyosmani