It's not that I don't understand how to find the integer square root of a number. I know several ways of finding them using Python and C++.
It's just that this algorithm is really messing with my brain. And having to write it in SML is another headache.
Please help me in understanding this algorithm. Do note that this should be using recursion:
The integer square root of is the integer such that ²≤<(+1)². The integer square root can be computed using the following inductive process:
- Compute the integer square root of = div 4 recursively. We then have that ²≤<(+1)².
- Since and are integers, we have that (+1)≤(+1)². We thus have (2)²≤4≤<4+4≤(2+2)².
- Hence we have that the integer square root of is either 2 or 2+1.
Write a recursive ML program corresponding to the above algorithm.