From a8b4dccc26e257135dbbe73b74be799491896488 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <vu3rdd@gmail.com>
Date: Thu, 25 Nov 2010 23:40:08 +0530
Subject: [PATCH] solution to 2.59 and 2.60

---
 src/sicp/ex2_59.rkt | 13 +++++++++++++
 src/sicp/ex2_60.rkt | 30 ++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)
 create mode 100644 src/sicp/ex2_59.rkt
 create mode 100644 src/sicp/ex2_60.rkt

diff --git a/src/sicp/ex2_59.rkt b/src/sicp/ex2_59.rkt
new file mode 100644
index 0000000..b00b1b3
--- /dev/null
+++ b/src/sicp/ex2_59.rkt
@@ -0,0 +1,13 @@
+#lang racket
+
+(require "ch2_3_3.rkt")
+
+(define (union-set set1 set2)
+  (cond ((null? set1) set2)
+        ((null? set2) set1)
+        ((element-of-set? (car set1) set2) (union-set (cdr set1) set2))
+        (else (cons (car set1) (union-set (cdr set1) set2)))))
+
+ (union-set '(1 2 3 4) '(5 6 7 8))
+ (union-set '(1 2 3 4) '(1 2 3 4))
+ (union-set '(1 2 3 4) '(1 2 7 8))
\ No newline at end of file
diff --git a/src/sicp/ex2_60.rkt b/src/sicp/ex2_60.rkt
new file mode 100644
index 0000000..ea9b304
--- /dev/null
+++ b/src/sicp/ex2_60.rkt
@@ -0,0 +1,30 @@
+#lang racket
+
+(define (element-of-set? x set)
+  (cond ((null? set) #f)
+        ((equal? x (car set)) #t)
+        (else (element-of-set? x (cdr set)))))
+
+(define (adjoin-set x set) 
+  (cons x set))
+
+(define (union-set set1 set2) 
+  (append set1 set2))
+
+(define (intersection-set set1 set2)
+  (cond ((or (null? set1) (null set2)) '())
+        ((element-of-set? (car set1) set2) (cons (car set1) (intersection-set (cdr set1) set2)))
+        (else (intersection-set (cdr set1) set2))))
+
+#|
+ union-set and adjoin-set has changed. Rest remain unchanged. 
+
+ Performance while adding a new element is O(1). Same with union. 
+ intersection-set remains the same - O(m * n). 
+ element-of-set? also remains the same - O (n).
+
+If duplicates are allowed, then Intersection and element-of-set? performance will degrade.
+
+|#
+
+  
\ No newline at end of file
-- 
2.45.2