David Evans Class 21: The Story So Far (Quicksort, Continuing Golden Ages) CS200: Computer Science University of Virginia.

Slides:



Advertisements
Similar presentations
Class 21: Imperative Programming University of Virginia cs1120 David Evans.
Advertisements

David Evans CS200: Computer Science University of Virginia Computer Science Lecture 13: Of On and Off Grounds Sorting.
Cs1120 Fall 2009 David Evans Lecture 16: Power Analysis.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 18: The Story So Far.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 16: Quicker Sorting.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 20: Sex, Religion, and Politics.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 14: Asymptotic Growth.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 11: 1% Pure Luck Make-up lab hours:
Cs1120 Fall 2009 David Evans Lecture 20: Programming with State.
Cs1120 Fall 2009 David Evans Lecture 19: Stateful Evaluation.
David Evans Class 12: Quickest Sorting CS150: Computer Science University of Virginia Computer Science Rose Bush by Jacintha.
David Evans Class 15: Golden Ages and Astrophysics CS200: Computer Science University of Virginia Computer Science.
David Evans Class 13: Quicksort, Problems and Procedures CS150: Computer Science University of Virginia Computer Science.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 12: Decrypting Work Circle Fractal.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 11: CS Logo, by Lincoln Hamilton and.
15 October 2003Computer Science1 David Evans ComputerScience.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 18: Think Globally, Mutate Locally.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
David Evans CS200: Computer Science University of Virginia Computer Science Class 17: Mutation M. C. Escher, Day and Night.
David Evans Class 20: Quick Sorting CS200: Computer Science University of Virginia Computer Science Queen’s University,
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 10: Puzzling Pegboards.
David Evans Class 19: Golden Ages and Astrophysics CS200: Computer Science University of Virginia Computer Science.
Class 37: Secret of Life CS200: Computer Science
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 36: Modeling Computing.
David Evans Lecture 13: Astrophysics and Cryptology CS200: Computer Science University of Virginia Computer Science.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 12: QuickSorting Queen’s University,
David Evans CS200: Computer Science University of Virginia Computer Science Class 16: Mutation M. C. Escher, Day and Night.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 19: Environments.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 5: Recursing on Lists.
David Evans Class 16: NP-Completeness / The Story so Far CS150: Computer Science University of Virginia Computer Science.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 18: Mutation M. C. Escher, Day and.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 9: Of On and Off Grounds Sorting Coffee.
Cs1120 Fall 2009 David Evans Lecture 18: Changing State Sounds of Colossus:
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 15: Intractable Problems (Smiley.
David Evans Class 15: P vs. NP (Smiley Puzzles and Curing Cancer) CS150: Computer Science University of Virginia Computer.
David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 8: Crash Course in Computational Complexity.
Lecture 3: Rules of Evaluation CS150: Computer Science
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 14: P = NP?
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 23: Intractable Problems (Smiley Puzzles.
1-2-Multiple Mr. Hudson Computer Science 1 Objective : Learn and be able to identify 1-way, 2-way, and Multiple- way sections.
David Evans CS200: Computer Science University of Virginia Computer Science Class 26: Halting Problem It is plain at any.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 8: Cons car cdr sdr wdr.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 9: Recursing Recursively Richard Feynman’s.
Lecture 4: Metacircles Eval Apply David Evans
Lecture 4: Evaluation Rules Recursion CS200: Computer Science
Lecture 13: Quicksorting CS200: Computer Science
Lecture 7: List Recursion CS200: Computer Science
Class 19: Think Globally, Mutate Locally CS150: Computer Science
Lecture 8: Recursion Practice CS200: Computer Science
Lecture 16: Quickest Sorting CS150: Computer Science
Lecture 20: Sex, Religion, and Politics CS150: Computer Science
Class 14: Intractable Problems CS150: Computer Science
Lecture 11: All Sorts CS200: Computer Science University of Virginia
David Evans Lecture 9: The Great Lambda Tree of Infinite Knowledge and Ultimate Power CS200: Computer Science University.
Lecture 13: Cost of Sorts CS150: Computer Science
Lecture 25: Metalinguistics > (meval '((lambda (x) (* x x)) 4)
Lecture 22: P = NP? CS200: Computer Science University of Virginia
Lecture 10: Quicker Sorting CS150: Computer Science
Lecture 26: The Metacircular Evaluator Eval Apply
Lecture 9: The Great Lambda Tree of Knowledge and Power
Cs1120 Fall 2009 David Evans Lecture 10: Fracturing Fractals cs1120 Fall 2009 David Evans
Lecture 3: Rules of Evaluation CS200: Computer Science
Lecture 15: Quicker Sorting CS150: Computer Science
Lecture 11: Sorting Grounds and Bubbles
Lecture 8: Recursing Lists CS150: Computer Science
Lecture 23: Computability CS200: Computer Science
Presentation transcript:

David Evans Class 21: The Story So Far (Quicksort, Continuing Golden Ages) CS200: Computer Science University of Virginia Computer Science

5 March 2004CS 200 Spring InsertSort-tree (define (insertel-tree cf el tree) (if (null? tree) (make-tree null el null) (if (cf el (get-element tree)) (make-tree (insertel-tree cf el (get-left tree)) (get-element tree) (get-right tree)) (make-tree (get-left tree) (get-element tree) (insertel-tree cf el (get-right tree)))))) (define (insertsort-tree cf lst) (define (insertsort-worker cf lst) (if (null? lst) null (insertel-tree cf (car lst) (insertsort-worker cf (cdr lst))))) (extract-elements (insertsort-worker cf lst)))  (log n ) n = number of elements in tree  ( n log n ) n = number of elements in lst

5 March 2004CS 200 Spring extract-elements We need to make a list of all the tree elements, from left to right. (define (extract-elements tree) (if (null? tree) null (append (extract-elements (get-left tree)) (cons (get-element tree) (extract-elements (get-right tree))))))

5 March 2004CS 200 Spring Quicksort C. A. R. (Tony) Hoare, 1962 Divide the problem into: –Sorting all elements in the list where (cf (car list) el) is true (it is < the first element) –Sorting all elements in the list where (not (cf (car list) el) is true (it is >= the first element) Will this do better?

5 March 2004CS 200 Spring Quicksort (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))))))

5 March 2004CS 200 Spring How much work is quicksort? (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)))))) What if the input list is sorted? Worst Case:  ( n 2 ) What if the input list is random? Expected:  ( n log 2 n )

5 March 2004CS 200 Spring Comparing sorts > (testgrowth insertsort-tree) n = 250, time = 20 n = 500, time = 80 n = 1000, time = 151 n = 2000, time = 470 n = 4000, time = 882 n = 8000, time = 1872 n = 16000, time = 9654 n = 32000, time = n = 64000, time = n = , time = ( ) > (testgrowth quicksort) n = 250, time = 20 n = 500, time = 80 n = 1000, time = 91 n = 2000, time = 170 n = 4000, time = 461 n = 8000, time = 941 n = 16000, time = 2153 n = 32000, time = 5047 n = 64000, time = n = , time = ( ) Both are  ( n log 2 n ) Absolute time of quicksort much faster

5 March 2004CS 200 Spring Good enough for VISA? n = , time = seconds to sort with quicksort  ( n log 2 n ) How long to sort 800M items? > (log 4) > (* (log )) > (/ (* (log )) 36) > (/ (* (log )) ) > (/ (* (log )) ) seconds ~ 4.5 days

5 March 2004CS 200 Spring Any other procedures we’ve seen that are more work than simulating the Universe?

5 March 2004CS 200 Spring PS4: Break Lorenz Cipher Procedure Try all possible wheel settings How many possible wheel settings: 5choices for first wheel * 5choices for second wheel * 5 choices for third wheel What is n ? –The number of wheels There are 5 n possible wheel settings

5 March 2004CS 200 Spring Lorenz Deciphering For PS4: you had 3 wheels, each with 5 possible settings: 5 3 = 125 combinations For WWII: Nazis has 12 wheels, each with more than 5 settings (up to 61 settings) 5 12 = possible combinations Bletchley Park’s cryptographers had to solve a problem that is times harder than PS4! (and had to figure out structure of Lorenz machine themselves)

5 March 2004CS 200 Spring Motivation Helps… Confronted with the prospect of defeat, the Allied cryptanalysts had worked night and day to penetrate German ciphers. It would appear that fear was the main driving force, and that adversity is one of the foundations of successful codebreaking. Simon Singh, The Code Book Having bombs dropping on you is at least 1 million times more motivating than getting a gold star!

5 March 2004CS 200 Spring Recap So far, we have been talking amount the work a procedure requires In a few weeks, we will learn how to talk about the amount of work a problem requires –That is, how much work is the best possible sorting procedure? –For the general sorting problem, you can’t do better than quicksort:  ( n log 2 n ) –But, VISA’s problem is simpler, so they can do much better:  ( n )

5 March 2004CS 200 Spring The Endless Golden Age Golden Age – period in which knowledge/quality of something doubles quickly At any point in history, half of what is known about astrophysics was discovered in the previous 15 years! Moore’s law today, but other advances previously: telescopes, photocopiers, clocks, etc.

5 March 2004CS 200 Spring Endless Golden Age and “Grade Inflation” Average student gets twice as smart and well-prepared every 15 years –You had grade school teachers (maybe even parents) who went to college! If average GPA in 1970 is 2.00 what should it be today (if grading standards didn’t change)?

5 March 2004CS 200 Spring Grade Inflation or Deflation? 2.00average GPA in 1970 (“gentleman’s C”?) * 2better students * 2better students * 3admitting women, non-whites (1971) * 1.54 population increase * 0.58increase in enrollment Virginia 19704,648,494 Virginia 20007,078,515 Average GPA today should be: 21.4 CS200 has only the best of the best students, and only the best 26/31 of them stayed in the course after PS1, so the average grade in CS200 should be 21.4*2*2*31/26 = Students ,000 Students ,848 (12,595 UG)

5 March 2004CS 200 Spring Short Golden Ages Golden Age – period in which knowledge/quality of something doubles quickly Endless golden age: at any point in history, the amount known is twice what was known 15 years ago Short golden age: knowledge doubles during a short, “golden” period, but only improves gradually most of the time

Average Goals per Game, FIFA World Cups Changed goalkeeper passback rule Goal-den age

5 March 2004CS 200 Spring The Real Golden Rule? Why do fields like astrophysics, medicine, biology and computer science (?) have “endless golden ages”, but fields like –music ( ) –rock n’ roll ( , or whatever was popular when you were 16) –philosophy (400BC-350BC?) –art ( ?) –soccer ( ) –baseball ( ) –movies ( ) have short golden ages? Thanks to Leah Nylen for correcting this (previously I had only , but that is only true for Hollywood movies).

5 March 2004CS 200 Spring The Story so Far…

5 March 2004CS 200 Spring The Liberal Arts Trivium (3 roads) language Quadrivium (4 roads) numbers GrammarRhetoricLogicArithmetic Geometry Music Astronomy From Lecture 1:

5 March 2004CS 200 Spring Liberal Arts Grammar: study of meaning in written expression Rhetoric: comprehension of verbal and written discourse Logic: argumentative discourse for discovering truth Arithmetic: understanding numbers Geometry: quantification of space Music: number in time Astronomy BNF replacement rules for describing languages, rules of evaluation for meaning Not yet… Interfaces between components (PS6-8), program and user (PS8) Rules of evaluation, if, recursive definitions Not much yet… wait until April Curves as procedures, fractals Yes, listen to “Hey Jude!” Yes: Neil deGrasse Tyson says so Trivium Quadrivium From Lecture 1:

5 March 2004CS 200 Spring Charge If you want to do something important and be remembered, work in a field that has a short golden age from –Shakespeare will be known a thousand years from now, but no one will have heard of any 21 st century playwright –Bach will be known a thousand years from now, but no 20 th century musician will be –Pele will be known a thousand years from now, but no one will remember Beckham, Ronaldo or Zidane