灯下 登录
计算机科学 / SICP / 1.2.2 Tree Recursion

Exercise 1.11 · 习题

Exercise 1.11: A function f is defined by
the rule that f
(
n
)
=
n if n

3 and f
(
n
)

=

f
(
n

1
)

+

2
f
(
n

2
)

+

3

f

(

n

3

) if n

3.

Write a procedure that computes f by means of a recursive process. Write a procedure that

computes f by means of an iterative process.

练习 1.11:函数 f 由如下规则定义:当 n < 3 时,f(n) = n;当 n ≥ 3 时,f(n) = f(n−1) + 2f(n−2) + 3f(n−3)。请分别写出一个用递归型计算过程计算 f 的过程,以及一个用迭代型计算过程计算 f 的过程。