SICP:1.2.3 Orders of Growth
SICP:1.2.3 Orders of Growth
本文逐段翻译 SICP 第二版 §1.2.3《Orders of Growth》,保留
R(n)、Θ notation、factorial/Fibonacci 的复杂度比较、资源增长直觉以及 Exercises 1.14–1.15 的原文顺序。
TL;DR
- Order of growth 用来粗略描述 input 变大时,process 消耗 computational resources 的增长速度。
- 若
R(n) = Θ(f(n)),则对于 sufficiently largen,R(n)被两个与n无关的 positive constant multiples off(n)夹住。 - Linear、exponential、logarithmic growth 描述了 problem size 改变时 resource requirement 的不同变化方式。
目录
| 章节 | 说明 |
|---|---|
| 1.2.3 Orders of Growth | resources 与 order of growth |
| Θ notation | R(n) = Θ(f(n)) 的定义 |
| Examples | factorial 与 Fibonacci 的 growth |
| Exercises 1.14–1.15 | counting change 与 sine |
1.2.3 Orders of Growth
前面的 examples 展示了:不同 processes 消耗 computational resources 的 rates 可能有很大差异。一种 convenient 的描述方式,是使用 order of growth 的 notion,在 inputs 变大时,对 process 所需 resources 进行 gross measurement。
令 n 是 measure problem size 的 parameter,令 R(n) 是 process 解决 size 为 n 的 problem 所需的 resources。在前面的 examples 中,我们令 n 是要计算给定 function 时所使用的 number,但还有其他 possibilities。例如,如果目标是计算一个 number 的 square root approximation,可以令 n 为所需的 digits accuracy;对于 matrix multiplication,可以令 n 为 matrices 的 rows 数量。
一般而言,针对 problem 的多个 properties 分析给定 process 都可能是 desirable 的。同样,R(n) 可以 measure 所使用的 internal storage registers 数量、执行的 elementary machine operations 数量,等等。在每次只执行 fixed number of operations 的 computers 中,所需 time 将与执行的 elementary machine operations 数量 proportional。
Θ notation
如果存在 positive constants k₁ 和 k₂,它们与 n 无关,使得对任意 sufficiently large 的 n 都成立:

那么我们说 R(n) 的 order of growth 是 
(f(n)),记作 R(n) = 
(f(n))(读作“theta of f(n)”)。换句话说,对于 large n,R(n) 被 k₁f(n) 与 k₂f(n) sandwich 在中间。
Examples
例如,对于 §1.2.1 描述的 linear recursive factorial process,steps 数量与 input n proportional。因此,该 process 所需 steps 的增长是 
(n)。我们还看到,它所需的 space 增长也是 
(n)。
对于 iterative factorial,steps 数量仍然是 
(n),但 space 是 
(1)——也就是 constant1。Tree-recursive Fibonacci computation 需要
(
<sup>n</sup>) steps 和 
(n) space,其中
是 §1.2.2 中描述的 golden ratio。
Orders of growth 只提供 process behavior 的 crude description。例如,需要 n² steps 的 process、需要 1000n² steps 的 process,以及需要 3n² + 10n + 17 steps 的 process,全部具有 
(n²) order of growth。
另一方面,order of growth 能有用地 indication:当我们改变 problem size 时,process behavior 会如何变化。对于 
(n)(linear)process,将 size double,大致会使使用的 resources double。对于 exponential process,problem size 每增加 1,resource utilization 就会乘以一个 constant factor。在 §1.2 的剩余部分,我们将考察两个 order of growth 为 logarithmic 的 algorithms;对它们而言,将 problem size double 只会使 resource requirement 增加一个 constant amount。
Exercises 1.14–1.15
Exercise 1.14
画出 §1.2.2 中 count-change procedure 在为 11 cents 换 change 时所生成 process 的 tree。随着 change amount 增大,这个 process 使用的 space 和 steps 数量的 orders of growth 是什么?
Exercise 1.15
一个以 radians 指定的 angle 的 sine,可以利用以下 approximation 计算:当 x sufficiently small 时,sin x
x;还可以利用下面的 trigonometric identity 来减小 sin argument 的 size:

(对于本 exercise,如果 angle 的 magnitude 不超过 0.1 radians,就认为它是“sufficiently small”。)以下 procedures 体现了这些 ideas:
(define (cube x) (* x x x))
(define (p x) (- (* 3 x) (* 4 (cube x))))
(define (sine angle)
(if (not (> (abs angle) 0.1))
angle
(p (sine (/ angle 3.0)))))
a. 在 evaluation (sine 12.15) 时,procedure p 被 applied 多少次?
b. 在 evaluation (sine a) 时,由 sine procedure 生成的 process 所使用的 space 和 steps 数量(作为 a 的 function)的 order of growth 是什么?
图与格式复核
- Θ inequality、sine identity 与 inline mathematical symbols 均保留原始 GIF,并放在原文对应位置。
- 本节没有独立的 large figure;复杂度 comparison、Exercises 1.14–1.15 与 Scheme code 顺序保持不变。
术语对照
| English | 译法/处理 |
|---|---|
| order of growth | 保留 order of growth;必要处译作增长阶 |
| resource requirement | 保留 resource requirement;必要处译作资源需求 |
| Θ notation | 保留 Θ notation;必要处译作 Θ 表示法 |
| linear / exponential / logarithmic | 保留 linear、exponential、logarithmic |
| internal storage register | 保留 internal storage register |
| elementary machine operation | 保留 elementary machine operation |
| space requirement | 保留 space requirement;必要处译作空间需求 |
| trigonometric identity | 保留 trigonometric identity;必要处译作三角恒等式 |
参考资料
- Harold Abelson、Gerald Jay Sussman、Julie Sussman:SICP 第二版 MIT Press 页面
- SICP HTML full text
- MIT OCW 6.001 Readings
-
原文脚注指出,这些 statements 隐含了相当多的 oversimplification。例如,如果把 process steps 计作 machine operations,就假设执行一次 multiplication 所需 machine operations 数量与被乘 numbers 的 size 无关;当 numbers 足够大时,这一假设是 false。Space estimates 也有类似问题。和 process 的 design 与 description 一样,process analysis 也可以在不同 abstraction levels 上进行。 ↩
评论 (0)