FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

docs: Improve comments and documentation in binary search algorithm by ITZ-NIHALPATEL · Pull Request #1849 · TheAlgorithms/JavaScript · GitHub

Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
29 changes: 22 additions & 7 deletions Recursive/BinarySearch.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
Loading

Back | FazBrowse Home | New Git URL