3 (define (element-of-set? x set)
5 ((equal? x (car set)) #t)
6 (else (element-of-set? x (cdr set)))))
8 (define (adjoin-set x set)
11 (define (union-set set1 set2)
14 (define (intersection-set set1 set2)
15 (cond ((or (null? set1) (null set2)) '())
16 ((element-of-set? (car set1) set2) (cons (car set1) (intersection-set (cdr set1) set2)))
17 (else (intersection-set (cdr set1) set2))))
20 union-set and adjoin-set has changed. Rest remain unchanged.
22 Performance while adding a new element is O(1). Same with union.
23 intersection-set remains the same - O(m * n).
24 element-of-set? also remains the same - O (n).
26 If duplicates are allowed, then Intersection and element-of-set? performance will degrade.