[SICP 연습] 132 연습 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
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[HTML] <div>와 <span>웹 페이지에서 공간을 분할하는 것은 중요합니다. 문서 구조를 쉽게 파악할 뿐만 아니라, 문제가 생기면 해당 부분만 건드리면 되기 때문이죠. 또한 분할을 하면 태그를 관리하기가 쉬워집니다. 웹 페이지의 공간을 분할 한...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.