Skip to content
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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

pranshu1402
Copy link
Contributor

No description provided.

Copy link
Owner

@khanchi97 khanchi97 left a 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

@pranshu1402
Copy link
Contributor Author

but binary search is used to search in sorted arrays only..??

@khanchi97
Copy link
Owner

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.
Copy link

@22shubh22 22shubh22 left a 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.

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.
Copy link

@22shubh22 22shubh22 left a 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

@pranshu1402
Copy link
Contributor Author

how to remove a file from commit?

@pranshu1402
Copy link
Contributor Author

actually that implementation has already been merged before

@22shubh22
Copy link

@khanchi97 please help.

@khanchi97
Copy link
Owner

@pranshu1402 if you want to change some files in your previous commits then take a look at this command git reset --soft commit_hash and google about this what it does and then you'll have a better idea, how to change files in your previous commits.
Actually what this command does is unstage all the files before that commit_hash then you can git add only those files which you want to commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants