内容 1.2 Procedures and the Processes They Generate · 25
练习 自检推理
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 的过程。
我的笔记 自动保存