Suppose we have a program that uses square roots, but often takes the square roots of the same numbers over and over again. We can speed it up by storing a Map associating values with their square roots. Every time the square root of some number is taken, we first consult the Map. If the number is present, we return the stored result rather than recomputing it. If not, we compute the square root (using Math. Sqrt ()), store the association in the Map, and return the result. This technique is called memoization. Write a method memoizedSqrt () that behaves as described. The Map must be a field in the class containing the method, not a variable within the method.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here