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

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.

## This note was uploaded on 07/09/2009 for the course CSE 6.046J/18. taught by Professor Piotrindykandcharlese.leiserson during the Fall '04 term at MIT.

### Page1 / 29

lecture02 - Introduction to Algorithms...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online