Skip to content

Fix lookups count in binary search #53

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion binary-search/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ describe('binarySearch', function() {
var indexOfElement = arrayLength - 4;
var lookingFor = proxyArray[indexOfElement];
var index = binarySearch(smartArray, lookingFor);
var lookupsCount = Object.keys(lookups).length;
//depending or implementation of binary search you can get 11 or 13 lookup count.
//both implementations are O(log(n)) but implementation with 11 lookup have a smaller constant, so are a little bit better.
assert(lookupsCount === 13 || lookupsCount === 11, 'lookup count should be equal 11 or 13. Your value is ' + lookupsCount);
assert.equal(index, indexOfElement);
assert.equal(Object.keys(lookups).length, 13);
});


Expand Down