{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lec1 - Lecture 1 Analyzing algorithms A royal mathematical...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
1/8/2009 1 Lecture 1: Analyzing algorithms A royal mathematical challenge (1202): Suppose that rabbits take exactly one month to become fertile, after which they produce one child per month, forever. Starting with one rabbit, how many are there after n months? Leonardo da Pisa, aka Fibonacci The proliferation of rabbits Fertile Not fertile Initially One month Two months Three months Four months Five months Rabbits take one month to become fertile, after which they produce one child per month, forever. Let F n be the number of rabbits at month n F 1 = 1 F 2 = 1 F n = F n-1 + F n-2 Fibonacci numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, … These numbers grow very fast: F 30 > 10 6 ! In fact, F n 2 0.694n 1.6 n , exponential growth . Computing Fibonacci numbers function Fib1(n) if n = 1 return 1 if n = 2 return 1 return Fib1(n-1) + Fib1(n-2) A recursive algorithm F(5) F(4) F(3) F(3) F(1) F(2) F(2) F(2) F(1) Two questions we always ask about algorithms: Does it work correctly? Yes – it directly implements the definition of Fibonacci numbers. How long does it take? This is not so obvious… Running time analysis function Fib1(n) if n = 1 return 1 if n = 2 return 1 return Fib1(n-1) + Fib1(n-2) Let T(n) = number of steps needed to compute F(n). Then: T(n) > T(n-1) + T(n-2) But F n = F n-1 + F n-2 . Therefore T(n) > F n 2 0.694n !
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern