Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

docs: Improve comments and documentation in binary search algorithm#1849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
ITZ-NIHALPATEL wants to merge2 commits intoTheAlgorithms:master
base:master
Choose a base branch
Loading
fromITZ-NIHALPATEL:master
Open
Changes fromall 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 deletionsRecursive/BinarySearch.js
View file
Open in desktop
Original file line numberDiff line numberDiff 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

[8]ページ先頭

©2009-2025 Movatter.jp