Skip to content

Comments

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

Open
gentoosiast wants to merge 1 commit intorolling-scopes-school:masterfrom
gentoosiast:master
Open

fix: provide correct tests to correspond to reference implementation of binary search#32
gentoosiast wants to merge 1 commit intorolling-scopes-school:masterfrom
gentoosiast:master

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