Miscellaneous problems · Exercise 78 of 100

Find a square root

To find the whole-number square root of a perfect square, start with a range of nonnegative guesses that contains the root. Square the middle guess. Since squares grow as the guesses grow, keep the upper half if the square is too small, keep the lower half if it is too large, and stop on equality.

Try it yourself

A square courtyard contains 196 identical square tiles. Each side has between 10 and 16 tiles inclusive. Using middle guesses, how many tiles are on one side?

One-step hint

Square the middle of the allowed range. Compare that square with 196 to decide which side of the range to keep for the next guess.

Worked solution
  1. The middle guess is 13. Its square is 169, so the side must be in the range from 14 through 16.
  2. The next middle guess is 15, whose square is 225. That leaves 14, and 14 times 14 gives exactly 196.
DSA compiler