University of Virginia, Department of Computer Science
CS200: Computer Science, Spring 2002

Notes: Monday 18 February 2002
Schedule

Link to All Code: http://www.cs.virginia.edu/cs200/notes/permutesort.ss

Permute Sort
(define (flat-one lst)
  (if (null? lst) lst (append (car lst) (flat-one (cdr lst)))))

(define (all-permutations lst)
  (flat-one
   (map
    (lambda (n)
      (if (= (length lst) 1)
          (list lst) ;; Only one permutation of 1-length list
          (map 
           (lambda (oneperm) (cons (nth lst n) oneperm))
           (all-permutations (exceptnth lst n)))))
    (intsto (length lst)))))

(define (is-sorted? cf lst)
  (or (null? lst) (= 1 (length lst)) 
      (and (cf (car lst) (cadr lst))
           (is-sorted? cf (cdr lst)))))

(define (permute-sort cf lst)
  (car 
   (filter (lambda (lst) (is-sorted? cf lst)) 
           (all-permutations lst))))
How much work is permute-sort?






What is a problem?






What does it mean to say a problem is O (n2)?






What does it mean to say a problem is Ω (n2)?






What does it mean to say a problem is in P?






What does it mean to say a problem is in NP?






Are all problems in P also in NP?






Are all problems in NP also in P?





Note: this is the Millennium Prize Problem: The P versus NP Problem. Clay Mathematics Institute will give you $1M if you answer it, so you may need more space.



CS 655 University of Virginia
Department of Computer Science
CS 200: Computer Science
David Evans
evans@virginia.edu
Using these Materials