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...

• Notes
• 44

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

Introduction to Algorithms Lecture 2 2 Recap 3 Today Master Theorem Divide-and-conquer paradigm Strassen’s algorithm Polynomial multiplication 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). 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 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 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! 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 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 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  #### You've reached the end of your free preview.

Want to read all 44 pages?

• Fall '05
• RudolfFleischer

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern  