T(0) = c, T(n) = T(n-1) + O(n) + ci
(count-leaves t) (if (leaf? t) 1 ...)which is 1 because t is a leaf, as stated above.
Induction:
Assume t is a tree of depth d+1 and that for any tree s of depth <= d that
(count-leaves s) is the number of leaves in s.
(count-leaves t) (if (leaf? t) 1 (+ (count-leaves (left t)) (count-leaves (right t)))) (+ (count-leaves (left t)) (count-leaves (right t)))by substitution, because t cannot be a leaf (d+1 is strictly greater than 1).
We also know that (left t) and (right t) are of depth at most d-1 by the definition of trees. Thus by the induction hypothesis, the sum (+ (count-leaves (left t)) (count-leaves (right t))) is the total number of leaves in t.
(define (running-sum <function>) (method ((l <list>) (cond ((null? l) (error "Empty List!")) ((null? (tail l)) l) (else: (pair (head l) (running-sum (pair (+ (first l) (second l)) (tail (tail l)))))))))
(define (compose-list <function>) (method ((l <list>)) (if (null? l) (method (x) x) (method (x) ((head l) ((compose-list (tail l)) x))))))
(define-class <glorp> (<object>)) (define-class <nurble> (<object>)) (define-class <foo> (<nurble>)) (define-class <bar> (<nurble>))