diff --git a/Recursive/BinarySearch.js b/Recursive/BinarySearch.js index ba622daaa1..7063b50d79 100644 --- a/Recursive/BinarySearch.js +++ b/Recursive/BinarySearch.js @@ -1,11 +1,26 @@ /** - * @function BinarySearch - * @description Search the integer inside the sorted integers array using Binary Search Algorithm. - * @param {Integer[]} arr - sorted array of integers - * @param {Integer} low - The input integer - * @param {Integer} high - The input integer - * @param {Integer} searchValue - The input integer - * @return {Integer} - return index of searchValue if found else return -1. + * @function binarySearch + * @description Recursively searches for a `searchValue` within a sorted `arr` of integers. + * This implementation uses default parameters for `low` and `high` to allow + * for a simple initial call (e.g., `binarySearch(arr, value)`). + * + * @example + * const arr = [1, 2, 3, 4, 5, 6, 7]; + * const value = 5; + * const index = binarySearch(arr, value); + * // index will be 4 + * + * @example + * const arr = [1, 2, 3, 4, 5, 6, 7]; + * const value = 8; + * const index = binarySearch(arr, value); + * // index will be -1 + * + * @param {Integer[]} arr - The sorted array of integers to search. + * @param {Integer} searchValue - The integer value to search for in the array. + * @param {Integer} [low=0] - The starting index of the subarray. (Primarily for internal recursive use). + * @param {Integer} [high=arr.length-1] - The ending index of the subarray. (Primarily for internal recursive use). + * @return {Integer} - The index of `searchValue` if found, otherwise -1. * @see [BinarySearch](https://en.wikipedia.org/wiki/Binary_search_algorithm) */