Private Readonly comparatorPrivate Readonly valuesStatic defaultStatic searchStatic method to perform binary search on an array
sorted array to search in
element to search for
optional comparator function
Default comparator function
index of the target element, or -1 if not found
Static searchStatic recursive method to perform binary search on an array
sorted array to search in
element to search for
optional comparator function
Default comparator function
index of the target element, or -1 if not found
Generated using TypeDoc
Binary Search algorithm Binary search is an efficient algorithm for finding an item from a sorted list of items. It works by repeatedly dividing in half the portion of the list that could contain the item.
Time Complexity: O(log n) Space Complexity: O(1) for iterative, O(log n) for recursive
Example
Example