CS200: Computer Science, Spring 2004

Notes: Monday 23 February 2004
Schedule
 Now: Exam 1
 Before Wednesday, 25 February's class: Read Neil DeGrasse Tyson, Science's Endless Golden Age. Neil DeGrasse Tyson is an astrophysicist who is director of the Rose Center for Earth and Space in New York. This short essay explains how what we know about the universe depends on orders of growth and Moore's law, and what skateboards, pierced belly buttons, and tattoos have to do with scientific progress.
 Friday, 5 March: Problem Set 5 (note: you have 2 extra days for PS5 from the original course schedule)
 Before 15 March: Read rest of GEB part I (Chapters 24 and 69, in addition to Chapters 1 and 5 you have already read).
Notes Upper bound O ("bigoh"): f(x) is O (g (x)) means there is a positive constant c such that c * f(x) < g(x) for all but a finite number of x values.Lower bound Ω ("omega"): f(x) is Ω (g (x)) means there is a positive constant c such that c * f(x) > g(x) for all but a finite number of x values.
 x^{2} is O (x^{2}) — c = .5 works fine
 x^{2} is O (x^{3}) — c = 1 works fine
 x^{3} is not O (x^{2}) — for any choice of c, once x gets big enough c * x^{3} > x^{2}
 Time to do TuttleSort for a list of length n is O (n^{2}) — the value of c depends on how fast our computer is
Tight bound Θ ("theta"): f(x) is Θ (g (x)) means that f(x) is O(g (x)) and f(x) is Ω (g (x)).
 x^{2} is Ω (x^{2}) — c = 2 works fine
 x^{2} is not Ω (x^{3}) — for any choice of c, once x gets big enough c * x^{2} < x^{3}
 x^{3} is Ω (x^{2}) — for any choice of c, once x gets big enough c * x^{3} > x^{2}
 Time to do TuttleSort for a list of length n is Ω (n^{2}) — the value of c depends on how fast our computer is.
 x^{2} is Θ (x^{2}) since x^{2} is O (x^{2}) and x^{2} is Ω (x^{2}).
 x^{2} is not Θ (x^{3}) since x^{2} is not Ω (x^{3})
 x^{3} is not Θ (x^{2}) since x^{3} is not O (x^{2})
 Time to do Tuttlesort for a list of length n is Θ (n^{2}) since it is O (n^{2}) and Ω (n^{2}).
Sorting Code Download: sorting.ss
(define (insertel cf el lst) (if (null? lst) (list el) (if (cf el (car lst)) (cons el lst) (cons (car lst) (insertel cf el (cdr lst)))))) (define (insertsort cf lst) (if (null? lst) null (insertel cf (car lst) (insertsort cf (cdr lst))))) (define (filter f lst) (insertl (lambda (el rest) (if (f el) (cons el rest) rest)) lst null)) (define (quicksort cf lst) (if (null? lst) lst (append (quicksort cf (filter (lambda (el) (cf el (car lst))) (cdr lst))) (list (car lst)) (quicksort cf (filter (lambda (el) (not (cf el (car lst)))) (cdr lst)))))) (define (sublist lst start end) (if (= start 0) (if (= end 0) null (cons (car lst) (sublist (cdr lst) start ( end 1)))) (sublist (cdr lst) ( start 1) ( end 1)))) (define (firsthalf lst) (sublist lst 0 (floor (/ (+ 1 (length lst)) 2)))) (define (secondhalf lst) (sublist lst (floor (/ (+ 1 (length lst)) 2)) (length lst))) (define (insertelh cf el lst) (if (null? lst) (list el) (let ((fh (firsthalf lst)) (sh (secondhalf lst))) (if (cf el (car fh)) (append (cons el fh) sh) (if (null? sh) (append fh (list el)) (if (cf el (car sh)) (append (insertelh cf el fh) sh) (append fh (insertelh cf el sh)))))))) (define (insertsorth cf lst) (if (null? lst) null (insertelh cf (car lst) (insertsorth cf (cdr lst))))) (define (maketree left el right) (list left el right)) (define (getleft tree) (first tree)) (define (getelement tree) (second tree)) (define (getright tree) (third tree)) (define (inserteltree cf el tree) (if (null? tree) (maketree null el null) (if (cf el (getelement tree)) (maketree (inserteltree cf el (getleft tree)) (getelement tree) (getright tree)) (maketree (getleft tree) (getelement tree) (inserteltree cf el (getright tree)))))) (define (extractelements tree) (if (null? tree) null (append (extractelements (getleft tree)) (cons (getelement tree) (extractelements (getright tree)))))) (define (insertsorttree cf lst) (define (insertsortworker cf lst) (if (null? lst) null (inserteltree cf (car lst) (insertsortworker cf (cdr lst))))) (extractelements (insertsortworker cf lst)))I am also the student whose 6th grade homeroom teacher wrote, "Less social involvement and more academic diligence is in order".
Neil deGrasse Tyson's Speech at the State Department to winners of the Presidential Awarded for Excellence in Mathematics and Science Teaching
cs200staff@cs.virginia.edu Using these Materials 