{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture02 - Introduction to Algorithms...

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

View Full Document Right Arrow Icon
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 2 Prof. Erik Demaine
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
Day 3 Introduction to Algorithms L2.2 Solving recurrences The analysis of merge sort from Lecture 1 required us to solve a recurrence. Recurrences are like solving integrals, differential equations, etc. o Learn a few tricks. Lecture 3 : Applications of recurrences.
Image of page 2
Day 3 Introduction to Algorithms L2.3 Substitution method 1. Guess the form of the solution. 2. Verify by induction. 3. Solve for constants. The most general method: Example: T ( n ) = 4 T ( n /2) + n [Assume that T (1) = Θ (1) .] Guess O ( n 3 ) . (Prove O and separately.) Assume that T ( k ) ck 3 for k < n . Prove T ( n ) cn 3 by induction.
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
Day 3 Introduction to Algorithms L2.4 Example of substitution 3 3 3 3 3 ) ) 2 / (( ) 2 / ( ) 2 / ( 4 ) 2 / ( 4 ) ( cn n n c cn n n c n n c n n T n T = + = + + = desired residual whenever ( c /2) n 3 n 0 , for example, if c 2 and n 1 . desired residual
Image of page 4
Day 3 Introduction to Algorithms L2.5 Example (continued) We must also handle the initial conditions, that is, ground the induction with base cases. Base: T ( n ) = Θ (1) for all n < n 0 , where n 0 is a suitable constant. For 1 n < n 0 , we have “ Θ (1) cn 3 , if we pick c big enough. This bound is not tight!
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
Day 3 Introduction to Algorithms L2.6 A tighter upper bound? We shall prove that T ( n ) = O ( n 2 ) . Assume that T ( k ) ck 2 for k < n : ) ( 4 ) 2 / ( 4 ) ( 2 n O n cn n n T n T = + + = Wrong! We must prove the I.H. 2 2 ) ( cn n cn = for no choice of c > 0 . Lose! [ desired residual ]
Image of page 6
Day 3 Introduction to Algorithms L2.7 A tighter upper bound! I DEA : Strengthen the inductive hypothesis. Subtract a low-order term.
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