Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions Recursive/BinarySearch.js
Original file line number Diff line number Diff line change
@@ -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)
*/

Expand Down