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

  • 相关阅读:
    计算GPS WGS_84 两点的距离
    极路由4_开ssh_刷breed
    aes-256-gcm_python3_php7_golang
    nginx_非标准端口_同端口_http_自动跳转_https
    配置sshd_除了特定ip外_仅密钥登录
    使用scp命令实现服务器之间文件传输
    Java防止重复提
    mysql使用SUBSTRING_INDEX截取部分字符串
    SEO大杀器rendertron安装
    PIC16 bootloader之I2C bootloader
  • 原文地址:https://www.cnblogs.com/NoMasp/p/4786068.html
Copyright © 2011-2022 走看看