2 ms·
Actually, it's clearly much closer to 4 than 5 - So I'd probably start at 4.1 or 4.2. There are 12 numbers from 4.0 through 5.0 inclusive - in steps of 0.1, an
by e12e 9y ago
Actually, it's clearly much closer to 4 than 5 - So I'd probably start at 4.1 or 4.2.
There are 12 numbers from 4.0 through 5.0 inclusive - in steps of 0.1, and there are 10 integer numbers from 16 through 25 inclusive - clearly there's an uneven, but still somewhat smooth mapping from one through the other via the square function (or root function, for that matter). It's easy to see (note that python rounds down up to .5 inclusive):
for i in range(40, 51):
n=i/10.0
print(n, round(n**2))
4.0 16
4.1 17
4.2 18
4.3 18
4.4 19
4.5 20
4.6 21
4.7 22
4.8 23
4.9 24
5.0 25
Now, for a computer algorithm, the couple of extra steps by using binary search doesn't really matter, but I find that when doing math by hand, it can be a great benefit to avail oneself of intuition, to be able to skip a few steps - especially when working in this manner where you "check your guess" at every step - so you won't risk a wrong answer, the only risk is wasted work.
This is indeed a bit different when approximating a more complicated function, eg one that doesn't monotonically increase/decrease.