Skip to content
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

Pseudo Code Binary Search lesson: v > m #16

Open
prb01 opened this issue Sep 21, 2022 · 4 comments
Open

Pseudo Code Binary Search lesson: v > m #16

prb01 opened this issue Sep 21, 2022 · 4 comments

Comments

@prb01
Copy link

prb01 commented Sep 21, 2022

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 specify n > v rather than v > m, where n = needle, v = value at midpoint, m = midpoint?

image

Thanks!

@echosonusharma
Copy link

echosonusharma commented Oct 2, 2022

@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;
}

@jameszenartist
Copy link

@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

@Agent-E11
Copy link

@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

@jameszenartist
Copy link

Hi @Agent-E11 , thank you for your reply!

Yes, that does make sense! -James

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

No branches or pull requests

4 participants