{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture02

# lecture02 - Introduction to Algorithms...

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

Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 2 Prof. Erik Demaine

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

View Full Document
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.
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.

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

View Full Document
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
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!

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

View Full Document
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 ]
Day 3 Introduction to Algorithms L2.7 A tighter upper bound! I DEA : Strengthen the inductive hypothesis. Subtract a low-order term.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

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