{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lec4 - EE 608 Computational Models and Methods Lecture 4...

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

View Full Document Right Arrow Icon
EE 608: Computational Models and Methods Lecture 4: Recurrences Read Chapter 4 and section 28.2 of Introduction to Algorithms
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
Recurrences A recurrence is an equation or inequality that describes a function in terms of its value(s) on smaller inputs. For example, the following recurrence describes the worst-case running time of MERGE-SORT : T ( n ) = Θ(1) if n = 1, 2 T ( n 2 ) + Θ( n ) n > 1. The solution to this equation is Θ( n lg n ). An important question is how can we find such a closed-form expression (exact or asymptotic) for recurrences? We will discuss 3 methods: Substitution method: Guess the bound and prove by induction. Iteration method: Treat it as summation. Master method: A “cookbook” method for solving T ( n ) = a T ( n b ) + f ( n ), a 1 , b > 1, and f ( n ) is a given function.
Image of page 2
An Example: MAX-MIN Write a procedure that returns the max and min of S. MAX-MIN ( S, p, r ) 1. if p r then exit(error) 2. if r = p + 1 3. then if S [ p ] > S [ r ] 4. then return ( S [ p ] , S [ r ]) 5. else return ( S [ r ] , S [ p ]) 6. else q p + r 2 7. ( max 1 , min 1 ) MAX-MIN ( S, p, q ) 8. ( max 2 , min 2 ) MAX-MIN ( S, q + 1 , r ) 9. return (max( max 1 , max 2 ) , min( min 1 , min 2 )) The recurrence for this routine is: T ( n ) = 1 if n = 2, 2 T ( n 2 ) + 2 n > 2. We want to find a closed form for this recurrence, as well as others.
Image of page 3

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

View Full Document Right Arrow Icon
Recurrences continued In practice, we often neglect certain details when we state and solve recur- rences. Sometimes we gloss over the assumption that the functions take integer arguments. For example, the MERGE-SORT worst-case running time is really: T ( n ) = Θ(1) if n = 1, T ( n 2 ) + T ( n 2 ) + Θ( n ) n > 1. We also typically don’t state the boundary conditions. For sufficiently small n , generally T ( n ) = Θ(1). Hence, we often report the recurrence simply as: T ( n ) = 2 T ( n 2 ) + Θ( n ) We omit floors, ceilings, and boundary conditions when they don’t matter. We also often solve for powers of 2 rather than all n (and in that case, we really haven’t shown the bound for all n ).
Image of page 4
The Substitution Method Example: Solve the recurrence: T ( n ) = 4 T ( n 2 ) + n, T (1) = 1. Guess to Verify by Induction: T ( n ) = O ( n 3 ), i.e., T ( n ) c n 3 . Base Case: T (1) = 1 c 1 3 = c , if c 1. Assume: T ( k ) c k 3 , for k < n . Inductive Step: T ( n ) = 4 T ( n 2 ) + n 4 c ( n 2 ) 3 + n = c 2 n 3 + n = c n 3 - c 2 n 3 + n = c n 3 - ( c 2 n 3 - n ) c n 3 , if c 2 , n 1
Image of page 5

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

View Full Document Right Arrow Icon
The Substitution Method continued How to make a good guess: Similarity to known function, e.g., T ( n ) = 2 T ( n 2 + 6) + n Start with a loose upper and lower bound and try to narrow it down. There are times when you can guess a bound but the math doesn’t work out in the induction. Sometimes the inductive assumption isn’t strong enough to prove a detailed bound; try subtracting a lower-order term. We will next show an example where this technique will help.
Image of page 6
The Substitution Method continued O ( n 3 ) is not a tight bound for T ( n ) = 4 T ( n 2 ) + n ; we can show that T ( n ) = O ( n 2 ).
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
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