News for hackers. Stuff that matters.
Re:Binary search with confidence by hddqsb on Monday March 07, 2022 @11:44AM (#30590027)
Note that with this version, the expected number of calls to `predicate` can be 1 more than strictly necessary (depending on n). This happens when n is one more than a power of 2, e.g. if n is 65 then `bit` is 64 and the first call will be `predicate(64)`, which is basically useless in reducing the search space.
Re:Binary search with confidence by orlp on Monday March 07, 2022 @02:40PM (#30592393)
This is true, if your comparison operator is very expensive you should (very, very carefully) implement the traditional binary search.