Learn the bisection method by finding the square root of a number -Step 9

I wanted to point out an error in the directions for this exercise. It claims that the square root of a number is always smaller than the number itself, which is not true. The square root of a number between zero and one is greater than the number itself. The directions should be rewritten for this step.

The code for this step sets the higher bound for the search to be the maximum of 1 and the input, which seems to take into account that the square root of a number can indeed be larger than the number itself. Since this module is in the beta stage, one might consider doing something similar for the lower bound as well, choosing zero if the number is less than one and choosing one otherwise. This wouldn’t make much difference, but it’s a thought.

In any event, the directions should be mathematically correct, and they should explain why we are using the maximum function for choosing the upper bound.

Hi there!

  1. Value 1
  2. Value 1/4

Which one is bigger?

I’m surprised at your reply. Are you asking me whether 1 or 1/4 is greater? If so, what does this have to do with square roots? My point was that the square root of a number can be larger than the number itself.

As a concrete example, the square root of 1/4 is 1/2. Clearly, the square root is larger than the original value. If you’d like further proof, simply plot the curves for the square root function and the identity function. You will see that the square root curve is higher for input values between 0 and 1. This is some pretty basic math, honestly.

Regarding the max function used when setting the high value: if we simply used the initial value itself as an upper bound, we would never find the square root for initial values less than 1. We would end up searching for, say, the square root of 1/4 between the values of 0 and 1/4. Again, the square root here is 1/2, and this value is not in the range 0 to 1/4. This is why it is necessary to use an upper bound of 1 for small input values.

The code makes sense, but the directions make a false statement. One might consider checking to see if the input (call it x) is greater or less than 1. If greater, search the interval (1, x). If less, search the interval (x, 1). The code works as-is, though. This would just be a slight improvement.