sicp-ex-4.29



<< Previous exercise (4.28) | Index | Next exercise (4.30) >>


felix021

 ; 
 ; 
 ; 
 ; a) with memoization´╝Ü0.43s, without memoization´╝Ü9.3s 
 (define (fib i) 
     (if (<= i 2) 
         1 
         (+ (fib (- i 1)) (fib (- i 2))))) 
  
 (define (test x) 
     (define (iter t) 
         (if (= t 0) 
             0 
             (+ x (iter (- t 1))))) 
     (iter 10)) 
  
 (test (fib 20)) 
  
 (exit) 

meteorgan

  
  
  
 with memoization: 
 (square (id 10)) 
 => 100 
 count 
 =>1 
  
 without memoization: 
 (square (id 10)) 
 =>100 
 count 
 =>2