Lecture03 - Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 3 Prof Erik Demaine The divide-and-conquer design paradigm 1 Divide the

Info iconThis 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
Background image of page 1

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

View Full DocumentRight 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.
Background 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
Background image of page 3

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

View Full DocumentRight 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 ) cf ( 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 ) .
Background image of page 4
Day 4 Introduction to Algorithms L3.5 Binary search Example: Find 9 35789 1 2 1 5 Find an element in a sorted array: 1. Divide: Check middle element. 2. Conquer: Recursively search 1 subarray. 3. Combine: Trivial.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Day 4 Introduction to Algorithms L3.6 Binary search Example: Find 9 35789 1 2 1 5 Find an element in a sorted array: 1. Divide: Check middle element. 2. Conquer: Recursively search 1 subarray. 3. Combine: Trivial.
Background image of page 6
Day 4 Introduction to Algorithms L3.7 Binary search Example: Find 9 35789 1 2 1 5 Find an element in a sorted array: 1. Divide: Check middle element. 2. Conquer: Recursively search 1 subarray. 3. Combine: Trivial.
Background image of page 7

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

View Full DocumentRight Arrow Icon
Day 4 Introduction to Algorithms L3.8 Binary search Example: Find 9 35789 1 2 1 5 Find an element in a sorted array: 1. Divide: Check middle element. 2. Conquer: Recursively search 1 subarray.
Background image of page 8
Image of page 9
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 / 27

Lecture03 - Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 3 Prof Erik Demaine The divide-and-conquer design paradigm 1 Divide the

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online