{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture03 - Introduction to Algorithms...

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

View Full Document Right Arrow Icon
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 3 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 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.
Image of page 2
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
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 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 ) .
Image of page 4
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.
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 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.
Image of page 6
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.
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
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.
Image of page 8
Image of page 9
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