{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture03

# lecture03 - Introduction to Algorithms...

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

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

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

View Full Document
Day 4 Introduction to Algorithms L3.2 The divide-and-conquer design paradigm 1. Divide the problem (instance) into subproblems. 2. Conquer the subproblems by solving them recursively. 3. Combine subproblem solutions.
Day 4 Introduction to Algorithms L3.3 Example: merge sort 1. Divide: Trivial. 2. Conquer: Recursively sort 2 subarrays. 3. Combine: Linear-time merge. T ( n ) = 2 T ( n /2) + O ( n ) # subproblems subproblem size work dividing and combining

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

View Full Document
Day 4 Introduction to Algorithms L3.4 Master theorem (reprise) T ( n ) = aT ( n / b ) + f ( n ) C ASE 1 : f ( n ) = O ( n log b a ε ) T ( n ) = Θ ( n log b a ) . C ASE 2 : f ( n ) = Θ ( n log b a lg k n ) T ( n ) = Θ ( n log b a lg k +1 n ) . C ASE 3 : f ( n ) = ( n log b a + ε ) and af ( n/b ) c f ( n ) T ( n ) = Θ ( f ( n )) . Merge sort: a = 2 , b = 2 n log b a = n C ASE 2 ( k = 0 ) T ( n ) = Θ ( n lg n ) .
Day 4 Introduction to Algorithms L3.5 Binary search Example: Find 9 3 5 7 8 9 12 15 Find an element in a sorted array: 1. Divide: Check middle element. 2. Conquer: Recursively search 1 subarray. 3. Combine: Trivial.

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

View Full Document
Day 4 Introduction to Algorithms L3.6 Binary search Example: Find 9 3 5 7 8 9 12 15 Find an element in a sorted array: 1. Divide: Check middle element. 2. Conquer: Recursively search 1 subarray. 3. Combine: Trivial.
Day 4 Introduction to Algorithms L3.7 Binary search Example: Find 9 3 5 7 8 9 12 15 Find an element in a sorted array: 1. Divide: Check middle element. 2. Conquer: Recursively search 1 subarray. 3. Combine: Trivial.

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

View Full Document
Day 4 Introduction to Algorithms L3.8 Binary search Example: Find 9 3 5 7 8 9 12 15 Find an element in a sorted array: 1. Divide: Check middle element. 2. Conquer: Recursively search 1 subarray.
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