摘要:
递归: (define (f n) (if (< n 3) n (+ (f (- n 1)) (* 2 (f (- n 2))) (* 3 (f (- n 3)))))) (f 3) 迭代: (define (f n) (if (< n 3) n (f-iter 0 1 2 n) )) (defin 阅读全文
摘要:
(define (first-denomination kinds-of-coin) (cond ((= kinds-of-coin 1) 1) ((= kinds-of-coin 2) 5) ((= kinds-of-coin 3) 10) ((= kinds-of-coin 4) 25) ((= 阅读全文
摘要:
树形递归:计算步骤 随输入 指数性 增长,空间 随输入 线性 增长. 线性迭代:计算步骤 随输入 线性 增长,空间 随输入 线性 增长. 用java写出来看看到底有多厉害: 树形递归程序运行时间:70805ms 而线性迭代绝大部分时候都是0ms. (Java里面函数名不允许 - 这个符号) 阅读全文
摘要:
(define (A x y) (cond ((= y 0) 0) ((= x 0) (* 2 y)) ((= y 1) 2) (else (A (- x 1) (A x (- y 1)))))) (A 1 10) (A 2 4) (A 3 3) (define (f n) (A 0 n))(f 0 阅读全文
摘要:
(define (plus-Recursive a b) (if (= a 0) b (inc (plus-Recursive (dec a) b)))) (define (inc n) (+ n 1)) (define (dec n) (- n 1)) (plus-Recursive 3 5) 从 阅读全文
摘要:
递归: (define (factorial n) (if (= n 1) 1 (* n (factorial(- n 1))))) (factorial 3) 迭代: (define (factorial n) (fact-iter 1 1 n)) (define (fact-iter produ 阅读全文
摘要:
(define (cube-root x) (cube-root-iter 1.0 x)) (define (cube-root-iter guess x) (if (good-enough? guess x) guess (cube-root-iter (improve guess x) x))) 阅读全文
摘要:
(define (sqrt-iter guess x) (if (good-enough? guess (improve guess x)) (improve guess x) (sqrt-iter (improve guess x) x))) (define (improve guess x)(a 阅读全文
摘要:
<一> (define (new-if predicate then-clause else-clause) (cond (predicate then-clause) (else else-clause))) (new-if (= 2 3) 0 5)(new-if (= 1 1) 0 5) new 阅读全文
摘要:
(define (sqrt-iter guess x) (if (good-enough? guess x) guess (sqrt-iter (improve guess x) x))) (define (improve guess x) (average guess (/ x guess))) 阅读全文