Open prb01 opened 2 years ago
@prb01 if the needle (n) is ahead of the middle value (m) then low should be mid + 1. there's some mess up in the sudo code....ignore that.
if (value === needle) {
return true;
} else if (needle > value) {
low = mid + 1;
} else {
high = mid;
}
@prb01 In addition, I recently noticed that he had set the initial value for hi as array.length. I've been looking for some good refreshers on algorithms lately, and I was always under the impression that it should be array.length - 1? Does that not matter?
-James
@jameszenartist I know this is over a year old, but I have an answer 🤣
hi
is exclusive, so the code does not check the value at hi
, only the values below hi
Hi @Agent-E11 , thank you for your reply!
Yes, that does make sense! -James
Not sure if this is the right place to raise this but FrontendMasters suggested raising an issue in the repo.
In the Pseudo Code Binary Search lesson, shouldn't the
else if
condition specifyn > v
rather thanv > m
, wheren = needle
,v = value at midpoint
,m = midpoint
?Thanks!