one slide summary
play

One-Slide Summary The basic recursive computation of Fibonacci can - PDF document

One-Slide Summary The basic recursive computation of Fibonacci can Costs take quite a while. There are faster ways . and We can formally measure and evaluate the cost Sneezewort of a computer program. We abstract away details such as


  1. One-Slide Summary • The basic recursive computation of Fibonacci can Costs take quite a while. There are faster ways . and • We can formally measure and evaluate the cost Sneezewort of a computer program. We abstract away details such as processor speed and instead and measure how the solving time increases as the Growth input increases . • g is in O(f) iff there exist positive constants c and n 0 such that g( n ) ≤ c f( n ) for all n ≥ n 0 . • If g is in O(f) we say that f is an upper bound for g. #1 #2 PS3 Attempts Outline • Sneezewort and Fibonacci • As of Wednesday, only 17 of you had • Cost of computing Fibonacci submitted anything for PS3. • Cost of sorting – ... with a high student score of 18/23. • Intro to Big-Oh Notation • Presumably the rest of you have allocated 13+ hours between now and Tuesday. :-) – Starting problem sets in this class “at the last minute” is the conceptual equivalent of Getting Involved in a Land War in Asia. #3 #4 Sneezewort • Achillea ptarmica is real. • It is “moste efficacious in the inflaming of the braine, and [is] "V" shrubbery therefore much used in Confusing by Andrew Jesien, Becky Elstad and Befuddlement Draughts, where the wizard is desirous of producing hot-headedness and recklessness.” – Order of the Phoenix, p.18 After the Incident • Sneezewort's pattern of by Ben Morrison and Liz Peterson development displays the Robot Cav Man Fibonacci sequence. by Jamie Jeon & Walter Borges #5 #6

  2. Sneezewort Growth Sneezewort Numbers 13 8? 5 3 2 1 1 First Time Unit Second Time Unit Offshoot pink by Jessica Geist, Ellen Clarke Could we model Sneezewort with PS3 code? #7 #8 Fibo Results Tracing Fibo >>> fibo(2) >>> (fibo 3) 1 | fibo(3) >>> fibo(3) | fibo(2) 2 | 1 >>> fibo(4) | fibo(1) 3 | 1 >>> fibo(10) |2 55 2 >>> fibo(60) Still working… Purple Arrow At least we finished. by Rachel Lathbury and Andrea Yoon by Dmitriy Semenov and Sara Alspaugh #9 #10 >>> fibo(5) A right-wing Christmas - awwwwww...... by Andrew Baker & Emily Lam |fibo(5) Liberal Arts Trivia: History | fibo(4) | |fibo(3) | | fibo(2) | | 1 • This 20 th -century American inventor is | | fibo(1) credited with the phonograph, the carbon | | 1 | |2 telephone transmitter, the practical electric | |fibo(2) | |1 light, and the phrase “Genius is one percent To calculate fibo(5) we calculated: | 3 fibo(4) 1 time inspiration, ninety-nine percent | fibo(3) fibo(3) 2 times | |fibo(2) perspiration.” He fought against Nikola Tesla's | |1 fibo(2) 3 times 5 times total | |fibo(1) fibo(1) 2 times alternating current in the so-called War of the | |1 = 8 calls to fibo Currents. | 2 = fibo(6), interestingly ... |5 How many calls to calculate fibo(60)? 5 #11 #12

  3. Liberal Arts Trivia: Film Studies Liberal Arts Trivia: Physics • In this Oscar-nominated 2006 film, David • Count Alessandro Antonio Anastasio Volta was Bowie is almost torched by Thomas Edison's a 19 th -century Italian physicist. Volta studied goons but invents a teleportation machine for what we now call capacitance, developing Wolverine so that he can defeat Batman in a separate means to study both electrical magic trick competition because he thinks potential V and charge Q , and discovering Batman killed his wife. that for a given object they are proportional. His experiments in “animal electricity”, in which two different metals were connected in series with frog's legs, eventually led to his most famous discovery. What was it? #13 #14 fast_fibo Fast-Fibo Results # 1 + 1 = 2 >>> fast_fibo(10) # 1 + 2 = 3 55 # 2 + 3 = 5 >>> a = time(); print fast_fibo(60); \ # 3 + 5 = 8 print time()-a 1548008755920 # a + b = fibo(n) 7.10487365723e-05 seconds def fast_fibo (n): def fib_helper (a, b, left): The original fibo would take at least 2.5 Trillion applications. A 2.5 GHz computer does 2.5 Billion simple operations per if left <= 0: second, so 2.5 Trillion applications operations take ~1000 return b seconds. Each application of fibo involves hundreds of simple return fib_helper(b, a+b, left-1) operations… return fib_helper(1, 1, n-2) #15 #16 # The Earth's mass is 6.0 x 10^24 kg >>> mass_of_earth = 6 * pow(10,24) # A typical rabbit's mass is 2.5 kilograms >>> 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.2326496895795693 According to Bonacci’s model, after less than 10 years, rabbits would out-weigh the Earth! Broccoli Fallout by Paul DiOrio, Rachel Phillips #17 #18

  4. Evaluation Cost Measuring Cost Actual running times • How does the cost scale vary according to: 80,000,000 with the size of the – How fast a processor 70,000,000 input ? you have 60,000,000 50,000,000 – How much memory • If the input size increases 40,000,000 you have by one, how much longer 30,000,000 – Where data is located 20,000,000 will it take? in memory 10,000,000 • If the input size doubles , – How hot it is 0 9 2 5 8 1 4 7 0 3 6 9 2 5 8 6 7 7 7 8 8 8 9 9 9 9 0 0 0 9 9 9 9 9 9 9 9 9 9 9 0 0 0 1 1 1 1 1 1 1 1 1 1 1 2 2 2 – What else is running how much longer will it Moore’s “Law” – computing power doubles – etc... Untitled take? every 18 months Nokomis McCaskill Chris Hooe #19 #20 Cost of Fibonacci Procedures Cost of Fibonacci Procedures def fast_fibo (n): def fast_fibo (n): def fibo (n): def fibo (n): def fib_helper(a, b, left): def fib_helper(a, b, left): if n <= 2: if n <= 2: if left <= 0: if left <= 0: return 1 return 1 return b return b return fibo(n-1) + fibo(n-2) return fibo(n-1) + fibo(n-2) return fib_helper(b, a+b, left-1) return fib_helper(b, a+b, left-1) return fib_helper(1, 1, n-2) return fib_helper(1, 1, n-2) Input fibo fast_fibo Input fibo fast_fibo m q mk m q mk m +1 m +1 q *Φ ( m +1) k ( m +1) k m +2 m +2 at least q 2 ( m +2) k at least q 2 ( m +2) k Φ = (1 + (sqrt 5)) / 2 = “ The Golden Ratio ” ~ 1.618033988749895... ~ fast-fibo(61) / fast-fibo(60 = 1.618033988749895 #21 #22 The Golden Ratio More Golden Ratios Parthenon Nautilus Shell #23 #24

  5. “You're The Best Around” Sorting def find_best (things, better): >>> def ascending(x,y): return x – y if len(things) == 1: return things[0] return pick_better(better, things[0], \ >>> sorted([5,2,4,1,3], ascending) find_best(things[1:], better) [1, 2, 3, 4, 5] def pick_better(better, a, b): >>> def descending(x,y): return y – x return (a if better(a,b) else b) >>> sorted([5,2,4,1,3], descending) def find_best (things, better): [1, 2, 3, 4, 5] return sorted(things, better)[0] >>> def longer(x,y): return len(x) – len(y) Which is faster and by how much? >>> sorted([“allons”,”enfants”,”de”],longer) [“de”, “allons”, “enfants”] #25 #26 Simple Sorting Simple Sort • Can we use find_best to # cf = comparison function implement sort? def sort (lst, cf): # simple sort – Yes! If not lst: return [] best = find_best(lst, cf) • Use find_best(lst) to return [best] + sort( \ find the best remove(lst, best), cf) • Remove it from the list – Adding it to the answer # remove(lst,x) = filter ... elt != x ... • Repeat until the list is crazy blue tree by Victor Malaret, Folami Williams empty #27 #28 Sorting Sorting Cost def sort (lst, cf): # simple sort • What grows? If not lst: return [] best = find_best(lst, cf) – n = the number of elements in lst return [best] + sort( \ • How much work are the pieces? remove(lst, best), cf) def find_best (things, better): find-best: if len(things) == 1: return things[0] return pick_better(better, things[0], \ remove: find_best(things[1:], better) def pick_better(better, a, b): return (a if better(a,b) else b) How much work is sort? #29 #30

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend