keshavsingh4522 / hacktoberfest

Submit Just 4 PRs to earn SWAGS and Tshirts🔥
https://hacktoberfest.digitalocean.com/
Creative Commons Zero v1.0 Universal
844 stars 3.95k forks source link

Update BinarySearch.java #4645

Closed ivikashgorai closed 7 months ago

ivikashgorai commented 8 months ago

What type of PR is this? (check all applicable)

Description

1) I changed "mid = (start + end) / 2" to "mid = start + (end - start) / 2" to ensure that the calculation of the middle index doesn't exceed the bounds of the integer range.

2)I modified the code to handle both ascending and descending order arrays and made slight adjustments to the return statement.

Add Link of GitHub Profile

https://github.com/ivikashgorai