guessing-game icon indicating copy to clipboard operation
guessing-game copied to clipboard

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

Open gentoosiast opened this issue 2 years ago • 2 comments

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;

gentoosiast avatar Jul 21 '22 10:07 gentoosiast

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

ghost avatar Jul 21 '22 10:07 ghost

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

AishSI avatar Jul 27 '22 12:07 AishSI