-
Notifications
You must be signed in to change notification settings - Fork 54
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added BinarySearch Implementation in java and readme file #148
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a good implementation try to use it.Its giving wrong answers.Try to run this
enter the size of the array : 6
enter element 1 : 6
enter element 2 : 4
enter element 3 : 3
enter element 4 : 2
enter element 5 : 1
enter element 6 : 8
Enter element to be searched : 1
Index from iterative binarySearch : -1
Index from recursive binarySearch : -1
How it can give -1 as a result
but binary search is used to search in sorted arrays only..?? |
So if user enters a value which is not sorted then it is your work to sort the array. |
Before Binary search the array must be sorted else it will give undefined results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Binary search of array gives index of array after sorting and not the original array index. Make necessary changes.
merging from original
Removed sorting of arrays after taking input.v because its a binary search it works only on sorted arrays. Its of no use on other arrays as it will then affect its time complexity as well as results. So asking user initially to enter the array only in increasing order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error in running binarysearch.java
how to remove a file from commit? |
actually that implementation has already been merged before |
@khanchi97 please help. |
@pranshu1402 if you want to change some files in your previous commits then take a look at this command |
No description provided.