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

Binary search: check for non-sorted input defeats the purpose of binary search #112

Closed
ryanplusplus opened this issue Apr 23, 2016 · 6 comments

Comments

@ryanplusplus
Copy link
Member

ryanplusplus commented Apr 23, 2016

Checking for non-sorted input is an O(n) operation. Performing the actual binary search is O(log(n)). Forcing the inclusion of an O(n) operation in the implementation of an O(log(n)) algorithm is confusing.

If you don't know that your input is sorted, there's no point in doing a binary search (sorting or checking for sorted input takes at least as long as a linear search), so I think this requirement should be removed.

@yurrriq
Copy link
Member

yurrriq commented Apr 23, 2016

You mean in the example implementation?

@ryanplusplus
Copy link
Member Author

The example implementation has this issue, but only because the tests require it to check for sorted input. The example is particularly inefficient because it is recursive and checks for sorted input on each invocation, but this is a moot point if the tests are updated.

@yurrriq
Copy link
Member

yurrriq commented Apr 23, 2016

Aha. I'd suggest you raise an issue on x-common as this pertains to more than just the Clojure track and it'd be good to solve it universally.

@ryanplusplus
Copy link
Member Author

There isn't a canonical test list for this exercise in x-common so for now this fix is only appropriate here. I'll put together a PR as long as you're in agreement that it should be fixed.

@yurrriq
Copy link
Member

yurrriq commented Apr 23, 2016

Definitely, but we should bring it up on x-common too.

@ryanplusplus
Copy link
Member Author

Created an issue in x-common: exercism/problem-specifications#234

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

No branches or pull requests

2 participants