|
University of Virginia Computer Science CS150: Computer Science, Fall 2005 |
(none) 21 September 2005 |
Exam 1s from previous CS200 courses are available here:
The exam will cover all material in the course through today's class (Class 13). Monday and Wednesday next week we will cover new material that is not included on Exam 1. On Friday next week, I will either answer questions that are sent to me by email before class or talk about how the Bletchley Park cryptographers really broke the Lorenz cipher.
(define (permute-sort cf lst)
(car
(filter (lambda (lst) (is-sorted? cf lst))
(all-permutations lst))))
(define (is-sorted? cf lst)
(or (null? lst) (= 1 (length lst))
(and (cf (car lst) (cadr lst))
(is-sorted? cf (cdr lst)))))
(define (all-permutations lst)
(flat-one
(map
(lambda (n)
(if (= (length lst) 1)
(list lst) ; The permutations of (a) are ((a)) (map
(lambda (oneperm)
(cons (nth lst n) oneperm))
(all-permutations (exceptnth lst n)))))
(intsto (length lst)))))
What is the time complexity of permute-sort?
What is a problem?
Why is it easier to establish an upper bound (O) for a problem than
a lower bound (Ω)?
| "); print ( $res[$first] ) ; print (" |
|
CS 150: Computer Science University of Virginia |
evans@virginia.edu Using these Materials |