Binary Search
Binary search algorithm is a search algorithm that finds the position of a target value within a sorted array.
Read full: wiki/binary_search_algorithm
Time complexity
O(log(n))
Import
import {binarySearch} from "@raikuxq/alg-ds/lib/exports/algorithms";
API reference:
Binary search API: /api/algorithms/binary-search
Example usage
import {binarySearch} from "@raikuxq/alg-ds/lib/exports/algorithms";
const arr = new Array(10).fill(undefined).map((item, index) => index + 1);
const foundElementIndex = binarySearch(arr, 5); // 4 (index is 4)