summaryrefslogtreecommitdiff
path: root/coding-exercises/2/59.rkt
diff options
context:
space:
mode:
authorMike Vink <mike1994vink@gmail.com>2023-03-27 21:58:09 +0200
committerMike Vink <mike1994vink@gmail.com>2023-03-27 21:58:09 +0200
commit5254a0befde355fca2711033f77047cf0bb5c08f (patch)
treeb6d07966babf647cd930bf82077f2d31985a8018 /coding-exercises/2/59.rkt
parentac1bf1b75868c873037f742b727e79ee5a97bae2 (diff)
moar
Diffstat (limited to 'coding-exercises/2/59.rkt')
-rw-r--r--coding-exercises/2/59.rkt5
1 files changed, 5 insertions, 0 deletions
diff --git a/coding-exercises/2/59.rkt b/coding-exercises/2/59.rkt
index e5f3289..b9193bd 100644
--- a/coding-exercises/2/59.rkt
+++ b/coding-exercises/2/59.rkt
@@ -1,15 +1,19 @@
#lang racket
;; unordered distinct list
+
+;; linear scan of the elements O(n)
(define (element-of-set? x myset)
(cond ((null? myset) false)
((equal? x (car myset)) true)
(else (element-of-set? x (cdr myset)))))
+;; O(n)
(define (adjoin-set x myset)
(if (element-of-set? x myset)
myset
(cons x myset)))
+;; linear scan of set1 and at each step we scan set2, O(n**2)
(define (intersection-set set1 set2)
(cond ((or (null? set1) (null? set2)) '())
((element-of-set? (car set1) set2)
@@ -18,6 +22,7 @@
(else (intersection-set (cdr set1) set2))))
(intersection-set (list 1 2 3) (list 'a 2 'c))
+;; linear scan of set1 and at each step we scan set2, O(n**2)
(define (union-set set1 set2)
(cond ((null? set1) set2)
((null? set2) set1)