English 中文(简体)
计划《空间与时间分析法》
原标题:Scheme Code Analysis for Space vs. Time

我通过麻省理工学院为古典6.001课程举办的网上讲座而工作: 计算机方案的结构和解释。

我试图从记忆使用到执行时间的角度了解分析代码的复杂性。 在前几场讲座中,他们提出了菲博克斯系列计划中的解决办法。

它们在录像中展示的解决办法是,具有X(Linear Recursion)记忆空间增长的特点,这给《菲克斯系列》带来了一个大问题。 当你试图找到更多的菲博克斯时,重新入侵所需的空间变得巨大。

他们建议设法取得线性循环性能,因为在整个计算过程中,所需的记忆空间始终保持不变,而斜线取决于X。

我的解决办法如下。 我的具体问题是,从记忆使用到执行时间来看,下文对我计划守则的绩效分析是什么?

(define (fib x)

  (define (fib-helper target total current-index i-2 i-1)
     (if (> current-index target)
            (if (= target 1)
                0
                total)
            (fib-helper target
                        (+ i-2 i-1)
                        (+ current-index 1)
                        i-1
                        (+ i-2 i-1))))

  (fib-helper x 1 3 0 1))
最佳回答

参考(fib n) causes n-1 电话fib-helper, 您的解决办法按时间顺序安排。 <代码>fib-helper 只打一次,每次一次,每次一次是尾声,因此你的节目在固定空间运行。

这意味着,打上<代码>(fib1000)的电话,只应在记号为(fib 100)时花10倍。

问题回答

参看你关于<代码>fib-helper的呼吁,这是一个适当的尾声,将持续运行。

我可以帮助你执行时间:





相关问题
Lisp code called from Java

Long story: I am doing a project for my functional programing class, and I thought of writing an AI controller in Lisp, for the Mario AI competition. I was looking over frameworks/libraries/ways of ...

Emacs, Zen-Coding mode, and Putty

I use emacs via Putty and since Putty doesn t send certain key combinations to the remote console I generally need to re-bind them to other key combinations. After installing the amazing Zen-Coding ...

In Which Cases Is Better To Use Clojure? [closed]

I develop in Lisp and in Scheme, but I was reading about Clojure and then I want to know, in which cases is better to use it than using Lisp or Scheme? Thanks

lambda-gtk negative pointer

I was trying to write my own put-pixel on (Gdk) pixbuf in Lisp. When I finally realized how I can operate on C pointers in CL, new obstacle came along - (gdk:pixbuf-get-pixels pb) returns me negative ...

Is there a common lisp package naming convention?

I have created some of my own user packages and have run into a name clash. In Java, the naming convention is to use your domain name in the package name: e.g. import com.example.somepackage;. Are ...

SOAP request from within an AutoLISP/AutoCAD macro

We have built a webservice for a client that uses AutoCAD. They have a macro that runs in AutoCAD that builds a SOAP request. But they have not figured out how to actually send() the soap request to ...

热门标签