1 / 23

Introduction: Efficient Algorithms for the Problem of Computing Fibonocci Numbers

Introduction: Efficient Algorithms for the Problem of Computing Fibonocci Numbers. Analysis of Algorithms. Prepared by John Reif, Ph.D. Readings. Main Reading Selection: CLR, Chapter 1. Goal. Devise Algorithms to solve problems on a TI calculator

casimir
Download Presentation

Introduction: Efficient Algorithms for the Problem of Computing Fibonocci Numbers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction: Efficient Algorithms for the Problem of Computing Fibonocci Numbers Analysis of Algorithms Prepared by John Reif, Ph.D.

  2. Readings • Main Reading Selection: • CLR, Chapter 1

  3. Goal • Devise Algorithms to solve problems on a TI calculator • assume each step(a multiplication, addition, or control branch) takes 1 m sec = 10-6 sec on 16 bit words

  4. Time Efficiency

  5. Fibonocci Sequence • 0, 1, 1, 2, 3, 5, 8, 13… • Recursive Definition • Fn = if n < 1 then n else Fn-1 + Fn-2 • Problem • Compute Fn for n=109 fast.

  6. Fibonacci Growth • Can show as n  ∞ • Golden ratio • So Fn ~ .45 ∙ 2 .7n is .7n bit number grows exponentially!

  7. Obvious Method n if n < 1 • Fn = > .01 n2 steps > 1016m sec for n = 109 = 1010 sec ~ 317 years! Fn-1 + Fn-2 if n > 1

  8. Wanted! • An efficient algorithm for Fn • Weapons: • Special properties of computational problems = combinatorics (in this case)

  9. Theorem: • Proof by Induction • Basis Step • Holds by definition for n=1 • Inductive Step • Assume holds for some n>0

  10. Inductive Step

  11. Powering Trick 1 1 1 0 • Fix M = • To compute Mn when n is a power of 2 For i=1 to log n do

  12. General Case of Powering • Decompose n = 2 j1 + 2 j2 + ... + 2 jkas sum of powers of 2 • Example • Compute

  13. Algorithm

  14. Bounding Mults • = 2 log n matrix products on symmetric matrices of size 2 x 2 • Each matrix product costs 6 integer mults • Total Cost = 12 (log n) integer mults > 360 for n = 109 integer mults

  15. Time Analysis • Fn ~ .45 2 .7n • So Fn is m = .7n bit integer • New method to compute Fn requires multiplying m bit number • BUT • Grammar School Method for Mult takes m2bool ops = m2/16 steps ~ 1016 steps for n = 109 ~ 1016msec ~ 1010 seconds ~ 317 years!

  16. Fast Multiplication of m bit integers a,b by • “Divide and Conquer” • seems to take 4 multiplications, but…

  17. 3 Mult Trick

  18. Recursive Mult Algorithm • Cost

  19. Schonhage-Strassen Integer Multiplication Algorithm • This is feasible to compute!

  20. Improved Algorithm • Computed Fn for n = 109using 360 = 12 log n integer mults each taking ~ 3 days • Total time to compute Fn • ~ 3 years with 1 msec/step

  21. How Did We Get Even MoreSpeed-Up? • New trick • a 2 log n mult algorithm (rather than n adds) • Old Trick • use known efficient algorithms for integer multiplication(rather than Grammar School mult) • Also used careful analysis of efficiency of algorithms to compare methods

  22. Problem (to be pondered later…) • How fast can 109 integers be sorted? • What algorithms would be used?

  23. Introduction: Efficient Algorithms for the Problem of Computing Fibonocci Numbers Analysis of Algorithms Prepared by John Reif, Ph.D.

More Related