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柯于旺 原创文章,如需转载请联系本人。

  • 相关阅读:
    正则表达式语法参考
    Informix触发器实例
    .net core 时间与时间戳的转换
    获取对象字段的值
    .NET 6 运行在Win7 SP1上出错解决方法
    写在2012,腊月二十八
    2011年度工作&生活总结
    终于在博客园上开通自己的blog了
    观察进程的内存占用情况
    从一个登录页面浅淡MVVM(二)
  • 原文地址:https://www.cnblogs.com/NoMasp/p/4786068.html
Copyright © 2011-2022 走看看