If you could help me with ANY part of this question, I would appreciate it. Thanks.
2^0 = 1
2^N = 2^(N-1) + 2^(N-1)
Convert this definition into an exactly equivalent tree-recursive function called two-to-the-power-of. Describe its asymptotic time complexity and explain why it has this time complexity.
Now write a function called tttpo_rec which computes the exact same thing, but which uses a linear recursive process which has an O(n) time complexity and also uses O(n) space for its pending operations.
Now write a function called tttpo_iter which computes the exact same thing, but which uses a linear iterative process which has an O(n) time complexity and also uses constant space.
Now let's say you want to generalize one of the preceding definitions so that it will handle arbitrary integer powers, so that you can compute 2^N, 3^N etc. Write a function called to-the-power-of that takes two arguments and raises one to the power of the other.
Here's the template:
;; to-the-power-of: integer integer -> integer
;; This function raises m to the power of n, returning the result.
;; m must be > 0 and n >= 0.
(define (to-the-power-of m n)
...)
(check-expect (to-the-power-of 1 0) 1) ; base case
(check-expect (to-the-power-of 2 3) 8) ; recursive case
(check-expect (to-the-power-of 3 2) 9) ; recursive case
We'll add one more restriction: you can't use the * operator; you can only use the following recursive function to do multiplications:
;;; multiply: integer integer -> integer
;; This function multiplies two non-negative integers, returning the result.
;; Its time complexity is O(a).
(define (multiply a b)
...)
Write the function, and describe what its time complexity is and why.