DOC PREVIEW
UVA CS 150 - Lecture 12: Something about Sneezewort

This preview shows page 1-2 out of 5 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1David Evanshttp://www.cs.virginia.edu/evansCS150: Computer ScienceUniversity of VirginiaComputer ScienceLecture 12: Something about SneezewortFrom Illustrations of the Britisch Flora(1924) by Walter Hood Fitchhttp://www.zum.de/stueber/fitch/high/IMG_8821.html2Lecture 12: SneezewortAfter the Incidentby Ben Morrison and Liz Peterson "V" shrubberyby Andrew Jesien, Becky ElstadRobot Cav Manby Jamie Jeon & Walter Borges 3Lecture 12: SneezewortSneezewort GrowthFirst Time Unit Second Time UnitOffshootCould we model Sneezewort with PS3 code?4Lecture 12: SneezewortSneezewort Numbers112358?13pinkby Jessica Geist, Ellen Clarke 5Lecture 12: SneezewortFibo Results> (fibo 2)1> (fibo 3)2> (fibo 4)3> (fibo 10)55> (fibo 60)Still working…At least we finished.by Dmitriy Semenov and Sara Alspaugh6Lecture 12: SneezewortTracing Fibo> (require-library "trace.ss")> (trace fibo)(fibo)> (fibo 3)|(fibo 3)| (fibo 2)| 1| (fibo 1)| 1|22Purple Arrowby Rachel Lathbury and Andrea Yoon27Lecture 12: Sneezewort> (fibo 5)|(fibo 5)| (fibo 4)| |(fibo 3)| | (fibo 2)| | 1| | (fibo 1)| | 1| |2| |(fibo 2)| |1| 3| (fibo 3)| |(fibo 2)| |1| |(fibo 1)| |1| 2|55To calculate (fibo 5) we calculated:(fibo 4) 1 time(fibo 3) 2 times(fibo 2) 3 times(fibo 1) 2 times= 8 calls to fibo = (fibo 6)How many calls to calculate (fibo 60)?5 times totalA right-wing Christmas - awwwwww......by Andrew Baker & Emily Lam 8Lecture 12: Sneezewortfast-fibo(define (fast-fibo n)(define (fib-helper a b left)(if (<= left 0)b(fib-helper b (+ a b) (- left 1))))(fib-helper 1 1 (- n 2)))9Lecture 12: SneezewortFast-Fibo Results> (fast-fibo 10)55> (time (fast-fibo 61))cpu time: 0 real time: 0 gc time: 025047307819612.5 Trillion applications2.5 GHz computer does 2.5 Billion simple operations per second, so 2.5 Trillion applications operations take ~1000 seconds. Each application of fibo involves hundreds of simple operations…10Lecture 12: SneezewortBeware the Bunnies!!;;; The Earth's mass is 6.0 x 10^24 kg> (define mass-of-earth (* 6 (expt 10 24)));;; A typical rabbit's mass is 2.5 kilograms> (define mass-of-rabbit 2.5)> (/ (* mass-of-rabbit (fast-fibo 60)) mass-of-earth)6.450036483e-013> (/ (* mass-of-rabbit (fast-fibo 120)) mass-of-earth)2.2326496895795693According to Bonacci’s model, after less than 10 years, rabbits would out-weigh the Earth!Beware the Sneezewort!!11Lecture 12: SneezewortBroccoli Falloutby Paul DiOrio, Rachel Phillips 12Lecture 12: SneezewortEvaluation CostActual running times vary according to:– How fast a processor you have– How much memory you have– Where data is located in memory– How hot it is– What else is running– etc...010,000,00020,000,00030,000,00040,000,00050,000,00060,000,00070,000,00080,000,00019691972197519781981198419871990199319961999200220052008Moore’s “Law” – computing power doubles every 18 months313Lecture 12: SneezewortMeasuring Cost• How does the cost scale with the size of the input• If the input size increases by one, how much longer will it take?• If the input size doubles, how much longer will it take?Nokomis McCaskillChris Hooe14Lecture 12: SneezewortCost of Fibonacci Procedures(define (fast-fibo n)(define (fib-helper a b left)(if (= left 0)b(fib-helper b (+ a b) (- left 1))))(fib-helper 1 1 (- n 2)))(define (fibo n)(if (or (= n 1) (= n 2))1 ;;; base case(+ (fibo (- n 1))(fibo (- n 2)))))m+1m+2z = mkqmfast-fibofiboInputq*Φ(m+1)k(m+2)kat least q2Φ = (/ (+ 1 (sqrt 5)) 2) = “The Golden Ratio” ~ 1.618033988749895...~ (/ (fast-fibo 61) (fast-fibo 60)) = 1.61803398874989515Lecture 12: SneezewortThe Golden RatioParthenon Nautilus Shell16Lecture 12: SneezewortMore Golden Ratioshttp://www.fenkefeng.org/essaysm18004.htmlby Oleksiy Stakhov17Lecture 12: SneezewortPS2 Question(define (find-best-hand hands)(car (sort hands higher-hand?))) (define (find-best lst cf)(if (= 1 (length lst)) (car lst)(pick-better cf (car lst) (find-best (cdr lst) cf))))(define (pick-better cf num1 num2)(if (cf num1 num2) num1 num2))(define (find-best-hand hands)(find-best hands higher-hand?))Which is better and by how much?18Lecture 12: SneezewortSimple Sorting• Can we use find-best to implement sort?• Use (find-best lst) to find the best• Remove it from the list• Repeat until the list is emptycrazy blue treeby Victor Malaret, Folami Williams419Lecture 12: SneezewortSimple Sort(define (sort lst cf)(if (null? lst) lst(let ((best (find-best lst cf)))(cons best (sort (delete lst best) cf)))))20Lecture 12: SneezewortSorting Hands(define (sort-hands lst)(sort lst higher-hand?))(define (sort lst cf)(if (null? lst) lst(let ((best (find-best lst cf)))(cons best (sort (delete lst best) cf)))))21Lecture 12: SneezewortSortingHow much work is sort?(define (sort lst cf)(if (null? lst) lst(let ((best (find-best lst cf)))(cons best (sort (delete lst best) cf)))))(define (find-best lst cf)(if (= 1 (length lst)) (car lst)(pick-better cf (car lst) (find-best (cdr lst) cf))))(define (pick-better cf num1 num2)(if (cf num1 num2) num1 num2))22Lecture 12: SneezewortSorting Cost• What grows?– n = the number of elements in lst• How much work are the pieces?find-best: work scales as n (increases by one)delete: work scales as n (increases by one)• How many times does sort evaluate find-best and delete? n• Total cost: scales as n223Lecture 12: SneezewortSorting CostIf we double the length of the list, the amount of work approximatelyquadruples: there are twice as many applications of find-best, and each one takes twice as long(define (sort lst cf)(if (null? lst) lst(let ((best (find-best lst cf)))(cons best (sort (delete lst best) cf)))))(define (find-best lst cf)(if (= 1 (length lst)) (car lst)(pick-better cf (car lst) (find-best (cdr lst) cf))))24Lecture 12: SneezewortTiming Sort> (time (sort < (revintsto 100)))cpu time: 20 real time: 20 gc time: 0> (time (sort < (revintsto 200)))cpu time: 80 real time: 80 gc time: 0> (time (sort < (revintsto 400)))cpu time: 311 real time: 311 gc time: 0> (time (sort < (revintsto 800)))cpu time: 1362 real time: 1362 gc time: 0> (time (sort < (revintsto 1600)))cpu time: 6650 real time: 6650 gc time: 0Cherry Blossomby Ji Hyun Lee, Wei Wang525Lecture 12: SneezewortTiming Sort050001000015000200002500030000350000 1000 2000 3000= n2/500measured times26Lecture 12: SneezewortCharge• Read Chapter 6: formal notations we will use for this type of analysis• PS4 out now: you know everything you need for the programming parts; we will cover more on analysis Wednesday and Friday• Beware


View Full Document

UVA CS 150 - Lecture 12: Something about Sneezewort

Documents in this Course
Objects

Objects

6 pages

Load more
Download Lecture 12: Something about Sneezewort
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 12: Something about Sneezewort and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 12: Something about Sneezewort 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?