The has a subtle issue (as discussed here) in that it can lead to overflow if low and high are sufficiently large enough. One way to avoid this is to calculate the midpoint as such
mid = low + ((high - low) / 2)
This is obviously not an issue in the illustration which is searching through a list of 6 animals, however it might be worth updating the implementation for general correctness. Thoughts?
Firstly, awesome project.
I remember reading that it's common in many implementations of binary search to calculate the midpoint as such
which is how it's calculated here.
The has a subtle issue (as discussed here) in that it can lead to overflow if
low
andhigh
are sufficiently large enough. One way to avoid this is to calculate the midpoint as suchThis is obviously not an issue in the illustration which is searching through a list of 6 animals, however it might be worth updating the implementation for general correctness. Thoughts?