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

fix: provide correct tests to correspond to reference implementation of binary search #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gentoosiast
Copy link

Supplied tests fail when reference implementation of binary search is tested against them. By reference implementation I mean binary search algorithm described in Wikipedia:
wiki
https://en.wikipedia.org/wiki/Binary_search_algorithm

Another example of reference implementation of binary search algorithm from the book McMillan - Data Structures & Algorithms with JavaScript (2014)
McMillan - Data Structures   Algorithms with JavaScript (2014)_01

Reference algorithm highlights:

  • guess = Math.floor((range_start + range_end) / 2);
  • if secret number is lower: range_end = attempt - 1;
  • if secret number is higher: range_start = attempt + 1;

@ghost
Copy link

ghost commented Jul 21, 2022

We need this fix because the old tests are designed for the wrong solution (where we can't reach the lower value of range)

@AishSI
Copy link

AishSI commented Jul 27, 2022

I suffered incredibly for an hour without this correction. It is necessary for the correct algorithm!

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.

2 participants