Searches for specific element in a given array using
the binary search algorithm.
Time complexity: O(log N).
Time complexity: O(log N).
- Source:
Parameters:
Name | Type | Description |
---|---|---|
array |
Array
|
Input array. |
value |
Number
|
Value of the element which index should be found. |
Returns:
- Type:
-
Number
Index of the element or -1 if not found.
Example
var search = require('path-to-algorithms/src/searching/'+
'binarysearch').binarySearch;
console.log(search([1, 2, 3, 4, 5], 4)); // 3