eli5: pseudo code that performs a binary search

166 views

I’ve only taken beginner python & there’s a lot of advanced answers online

In: 0

2 Answers

Anonymous 0 Comments

Now this is more psuedo than code but it’s a great explanation of the basic concept behind binary search.

If you’re looking for a specific number in a sorted number book. Go to the center of the book, if your number is smaller than the “middle” number, keep the first half of the book. If your number is larger keep the second half.

Now with the half book, go to the middle of the half book and check the “middle” number. If your number is smaller keep the first half of the half-book, if it’s larger keep the second half of the half-book.

Rinse and repeat.

Eventually you’ll end up with the number you’re looking for (if it exists).

You are viewing 1 out of 2 answers, click here to view all answers.