博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【SICP练习】132 练习3.63
阅读量:6650 次
发布时间:2019-06-25

本文共 1111 字,大约阅读时间需要 3 分钟。

练习3-63

原文

Exercise 3.63. Louis Reasoner asks why the sqrt-stream procedure was not written in the following more straightforward way, without the local variable guesses:

(define (sqrt-stream x)    (cons-stream 1.0                       (stream-map (lambda (guess)                                                              (sqrt-improve guess x))                                                                (sqrt-stream x))))

Alyssa P. Hacker replies that this version of the procedure is considerably less efficient because it performs redundant computation. Explain Alyssa’s answer. Would the two versions still differ in efficiency if our implementation of delay used only (lambda () ) without using the optimization provided by memo-proc (section 3.5.1)?

分析

书中第233页的sqrt-stream和Louis的相比差别在于其用了gusses作为返回结果,而其是一个流。其每一次的运算都会调用上一次的结果,仅仅是多计算一次。因为有了memo-proc,复杂度就是theta(n)。

虽然Louis也是返回流,但是它相比于书中的定义,不是从上一次开始调用而是从n=1开始。因此对于任意的计算,其都需要n步。所以它的复杂度是theta(n^2)。

而如果去掉了sqrt-stream的memo-proc,则两者的效果是相同的,因为其实通过guesses来维持着流以达到memo-proc的效果。而Louis的定义则没有依靠memo-proc。



感谢您的访问,希望对您有所帮助。 欢迎大家关注或收藏、评论或点赞。


为使本文得到斧正和提问,转载请注明出处:


你可能感兴趣的文章
apache 访问权限基本设置
查看>>
jQuery的deferred对象详解
查看>>
python基础知识~ 序列化
查看>>
函数作业
查看>>
开发经理的职责
查看>>
FinalData 数据恢复工具[绿色版]
查看>>
linux vim
查看>>
莫比乌斯反演
查看>>
新SQL temp
查看>>
两个有序数组的合并
查看>>
JZ-C-29
查看>>
声明式事务xml Spring
查看>>
Activity的启动模式(android:launchMode)
查看>>
CQOI2007 涂色 paint (区间dp)
查看>>
Bootstrap定制(二)less基础语法
查看>>
js 数组排序
查看>>
android笔记--处理started service的多次启动请求(转)
查看>>
UE4 学习笔记1 变量的初始化
查看>>
基本子类设计
查看>>
编码和解码
查看>>