lecture2.ppt - Introduction to Algorithms Lecture 2 Recap 2 Today • • • • Master Theorem Divide-and-conquer paradigm Strassen’s algorithm

lecture2.ppt - Introduction to Algorithms Lecture 2 Recap 2...

This preview shows page 1 - 11 out of 44 pages.

Introduction to Algorithms Lecture 2
Image of page 1
2 Recap
Image of page 2
3 Today Master Theorem Divide-and-conquer paradigm Strassen’s algorithm Polynomial multiplication
Image of page 3
4 Master method Idea : solve class of recurrences of form T ( n ) = aT ( n / b ) + f ( n ) a 0 and b 0 , and f asymptotically positive. Abstractly: T ( n ) is runtime for an algorithm; it’s u nknown, but we do know that: a subproblems of size n / b are solved recursively, each i n time T ( n / b ) . f ( n ) is the cost of dividing problem (beforehand) and co mbining the results (afterward).
Image of page 4
5 Recursion tree f ( n ) f ( n / b ) f ( n / b ) f ( n / b ) f ( n / b 2 ) f ( n / b 2 ) f ( n / b 2 ) f ( n / b 2 ) ……….. ……….. a a a a a a a ……….. (1) (1) (1) (1) (1) (1) ……….. n a b b a n log log f ( n ) af ( n / b ) a 2 f ( n / b 2 ) ) ( log a b n Total: 1 log 0 log ) / ( ) ( n j j j a b b b n f a n n b log
Image of page 5
6 Analysis #of leaves = Iterating the recurrence (expanding the tree) yields T ( n ) = f ( n ) + aT ( n / b ) = f ( n ) + af ( n / b ) + a 2 T ( n / b 2 ) = f ( n ) + af ( n / b ) + a 2 f ( n / b 2 ) +… + n a b b a n log log ) 1 ( ) / ( log 1 log 1 log T a b n f a n n n b b b
Image of page 6
7 Intuition Three common cases: Running time dominated by cost at leaves. Running time evenly distributed throughout tree Running time dominated by cost at root Thus, to solve recurrence we need only characterize the dominant term in each case!
Image of page 7
8 In each case, compare f ( n ) and Case 1 : for some constant 0 . f ( n ) grows polynomially slower than Weight of each level increases geometrically fr om root to leaves ( 1, a 1 , a 2 ,… ) Leaves contain constant fraction of total weight ; i.e., total is constant #of leaves. the work at leaves dominates. a b n log ) ( ) ( log a b n O n f a b n log
Image of page 8
9 Analysis of Case 1 a j n j j n j j j b b b b n a O b n f a log 1 log 0 1 log 0 ) / ( a n a n j j a n j j a a b b b b b b b b n O b b n O b n O b ab n O log log log 1 log 0 log 1 log 0 log log 1 1 Thus ) ( ) ( log a b n n T
Image of page 9
10 Case 2 for some constant k 0 f ( n ) and same to within a polylogarit hmic factor (log to a power) Weight decreases from root to leaves Thus
Image of page 10
Image of page 11

You've reached the end of your free preview.

Want to read all 44 pages?

  • Fall '05
  • RudolfFleischer

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

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors