-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vinit Shahdeo
committed
Dec 7, 2019
1 parent
aee18fc
commit 810be77
Showing
9 changed files
with
38 additions
and
38 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,32 +1,32 @@ | ||
// This file contains all the pure utility functions | ||
|
||
/** | ||
* | ||
* | ||
* @param {Array} arr the array in which the function will search for the element | ||
* @param {Number} element element to be searched | ||
* @param {Number} start starting index of the array | ||
* @param {Number} end last index of the array | ||
* @description This is an implementation of Binary search algorithm. | ||
* We might use this for searching operation | ||
*/ | ||
const binarySearch = function (arr, element, start, end) { | ||
const binarySearch = function (arr, element, start, end) { | ||
if (start > end) { | ||
return false; | ||
return false; | ||
} | ||
var mid = Math.floor((start + end)/2); | ||
if ( arr[mid] === element) { | ||
return true; | ||
|
||
var mid = Math.floor((start + end) / 2); | ||
|
||
if (arr[mid] === element) { | ||
return true; | ||
} | ||
if(arr[mid] > element) { | ||
return binarySearch(arr, element, start, mid-1); | ||
|
||
if (arr[mid] > element) { | ||
return binarySearch(arr, element, start, mid - 1); | ||
} | ||
|
||
else { | ||
return binarySearch(arr, element, mid+1, end); | ||
} | ||
} | ||
return binarySearch(arr, element, mid + 1, end); | ||
} | ||
}; | ||
|
||
module.exports = binarySearch; |