Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up# Added BinarySearch algorithm #1389
Conversation
Searches for an element inside a sorted array in O(logn) time complexity
|
|
||
| public class BinarySearch { | ||
|
|
||
| static int binarySearch(int[] a, int x, int left, int right) { |
| int mid = (right-left)/2; | ||
| if(left<right) |
rbshealy
Aug 5, 2020
Contributor
Add whitespace to make your code more readable
int mid = (right-left)/2;
if(left<right)
| if(a[mid] ==x) | ||
| return mid; | ||
| else if(a[mid]>x) | ||
| return binarySearch(a, x, left, mid); | ||
| else if(a[mid]<x) | ||
| return binarySearch(a, x, mid+1, right); | ||
| else | ||
| return -1;} | ||
| else if(left ==right) | ||
| {if(a[mid] ==x) | ||
| return mid;} | ||
| return -1; |
rbshealy
Aug 5, 2020
Contributor
Please use indentation and brackets, and clean up these if else-if statements
This is hard to read
| int[] a = new int[n]; | ||
| for (int i = 0; i < n; i++) { |
rbshealy
Aug 5, 2020
Contributor
add white space between declaration/assignment and logic
i.e.
int[] a = new int[n];
for (int i = 0; i < n; i++) {
|
Sent from Yahoo Mail for iPhone
On Thursday, August 6, 2020, 3:36 am, Huzaib <notifications@github.com> wrote:
@Huzaib commented on this pull request.
In divideconquer/BinarySearch.java:
+ int[] a = new int[n];
+ for (int i = 0; i < n; i++) {
Ok I am on it
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
|
Sir, will you look at it now? |
Oddly enough I can't see the changes you've made |
|
Sorry sir, it was my mistake |
|
Resolve all issues and then Ill take another look |
|
I think everything is done |
|
It seems your code has a lot of unnecessary whitespaces, please delete it, you don't need every whitespace after a single line. Just place it for a necessary code only |
|
|
||
| public class BinarySearch { | ||
|
|
||
| public static int binarySearch(int[] a, int x, int left, int right) { |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Searches for an element inside a sorted array in O(logn) time complexity