如果你能帮助我这个问题的任何部分,我将不胜感激。谢谢。树递归/时间复杂度计划分配
2^0 = 1
2^N = 2^(N-1) + 2^(N-1)
转换这个定义为所谓的两到最电源的完全等同树递归函数。描述其渐近时间复杂性并解释为什么它具有这种时间复杂性。
现在编写一个名为tttpo_rec的函数,它计算完全相同的东西,但它使用具有O(n)时间复杂度的线性递归过程,并且还为其挂起的操作使用O(n)空间。
现在编写一个称为tttpo_iter的函数,它计算完全相同的东西,但它使用具有O(n)时间复杂度并且也使用恒定空间的线性迭代过程。
现在让我们假设你想概括一个前面的定义,以便它可以处理任意的整数幂,这样你就可以计算2^N,3^N等等。编写一个函数叫做to-the-power-这需要两个论点,并且提出另一个论点的力量。
这里是模板:
;; 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
我们将增加一个限制:不能使用*运算符;你只能使用下面的递归函数做乘法:
;;; multiply: integer integer -> integer
;; This function multiplies two non-negative integers, returning the result.
;; Its time complexity is O(a).
(define (multiply a b)
...)
写的功能,并介绍它的时间复杂度和原因。