zoukankan      html  css  js  c++  java
  • 【SICP练习】132 练习3.63

    练习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。



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


    为使本文得到斧正和提问,转载请注明出处:
    http://blog.csdn.net/nomasp


    版权声明:本文为 NoMasp柯于旺 原创文章,如需转载请联系本人。

  • 相关阅读:
    兼容火狐回车事件
    html的锚链接位置偏差解决
    jq记住密码
    PHP界面显示中文乱码
    ThinkPHP5.0学习1
    Fatal error: Call to undefined function pasterTempletDiy()
    dede问答模块修改
    PHP:Deprecated: Function set_magic_quotes_runtime() is deprecated 错误
    jq根据文本显示内容设置样式
    Tomcat Remote Debug操作和原理
  • 原文地址:https://www.cnblogs.com/NoMasp/p/4786068.html
Copyright © 2011-2022 走看看