|
1 | 1 | /** |
2 | | - * @function BinarySearch |
3 | | - * @description Search the integer inside the sorted integers array using Binary Search Algorithm. |
4 | | - * @param {Integer[]} arr - sorted array of integers |
5 | | - * @param {Integer} low - The input integer |
6 | | - * @param {Integer} high - The input integer |
7 | | - * @param {Integer} searchValue - The input integer |
8 | | - * @return {Integer} - return index of searchValue if found else return -1. |
| 2 | + * @function binarySearch |
| 3 | + * @description Recursively searches for a `searchValue` within a sorted `arr` of integers. |
| 4 | + * This implementation uses default parameters for `low` and `high` to allow |
| 5 | + * for a simple initial call (e.g., `binarySearch(arr, value)`). |
| 6 | + * |
| 7 | + * @example |
| 8 | + * const arr = [1, 2, 3, 4, 5, 6, 7]; |
| 9 | + * const value = 5; |
| 10 | + * const index = binarySearch(arr, value); |
| 11 | + * // index will be 4 |
| 12 | + * |
| 13 | + * @example |
| 14 | + * const arr = [1, 2, 3, 4, 5, 6, 7]; |
| 15 | + * const value = 8; |
| 16 | + * const index = binarySearch(arr, value); |
| 17 | + * // index will be -1 |
| 18 | + * |
| 19 | + * @param {Integer[]} arr - The sorted array of integers to search. |
| 20 | + * @param {Integer} searchValue - The integer value to search for in the array. |
| 21 | + * @param {Integer} [low=0] - The starting index of the subarray. (Primarily for internal recursive use). |
| 22 | + * @param {Integer} [high=arr.length-1] - The ending index of the subarray. (Primarily for internal recursive use). |
| 23 | + * @return {Integer} - The index of `searchValue` if found, otherwise -1. |
9 | 24 | * @see [BinarySearch](https://en.wikipedia.org/wiki/Binary_search_algorithm) |
10 | 25 | */ |
11 | 26 |
|
|
0 commit comments