# L03 - Divide and Conquer Divide Given some problem divide...

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

CS0250, Set 3 Divide and Conquer Divide Given some problem, divide it into a number of similar, but smaller sub-problems. Solve each of these problems recursively . Conquer (or Combine) Combine the solutions of each of these sub-problems into a solution of the original problem.

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

View Full Document
CS0250, Set 3 Sort(a 1 ,a 2 ,…,a n ) { S1=Sort(a 1 ,a 2 ,…,a n/2 ); S2=Sort(a n/2+1 ,…,a n ); merge S1 and S2 into a single sorted list. } An Example: MergeSort
CS0250, Set 3 A sample run 12 5 67 32 20 9 39 78 12 5 67 32 20 9 39 78 12 5 67 32 39 78 20 9 12 5 67 32 20 9 39 78

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

View Full Document
CS0250, Set 3 12 5 67 32 20 9 39 78 12 5 67 32 20 9 39 78 5 12 67 32 39 78 20 9 12 5 67 32 20 9 39 78
CS0250, Set 3 12 5 67 32 20 9 39 78 12 5 67 32 20 9 39 78 5 12 32 67 39 78 20 9 12 5 67 32 20 9 39 78

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

View Full Document
CS0250, Set 3 12 5 67 32 20 9 39 78 5 12 32 67 20 9 39 78 5 12 32 67 39 78 20 9 12 5 67 32 20 9 39 78
CS0250, Set 3 12 5 67 32 20 9 39 78 5 12 32 67 20 9 39 78 5 12 32 67 39 78 9 20 12 5 67 32 20 9 39 78

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

View Full Document
CS0250, Set 3 12 5 67 32 20 9 39 78 5 12 32 67 20 9 39 78 5 12 32 67 39 78 9 20 12 5 67 32 20 9 39 78
CS0250, Set 3 12 5 67 32 20 9 39 78 5 12 32 67 9 20 39 78 5 12 32 67 39 78 9 20 12 5 67 32 20 9 39 78

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

View Full Document
CS0250, Set 3 5 9 12 20 32 39 67 78 5 12 32 67 9 20 39 78 5 12 32 67 39 78 9 20 12 5 67 32 20 9 39 78
CS0250, Set 3 How to merge two sorted lists 5 9 22 67 88 92 12 34 78 98

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

View Full Document
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5 9

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

View Full Document
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5 9 12
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5 9 12 22

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

View Full Document
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5 9 12 22 34
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5 9 12 22 34 67

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

View Full Document
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5 9 12 22 34 67 78
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5 9 12 22 34 67 78 88

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

View Full Document
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5 9 12 22 34 67 78 88 92
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5 9 12 22 34 67 78 88 92 98 We can merge two sorted lists of n numbers in O(n) time.

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

View Full Document
CS0250, Set 3 Time complexity Sort(a 1 ,a 2 ,…,a n ) { S1=Sort(a 1 ,a 2 ,…,a n/2 ); S2=Sort(a n/2+1 ,…,a n ); merge S1 and S2 into a single sorted list. } Thus, What's T(n)? T(n) T(n/2) T(n/2) n n n T n T + = ) 2 / ( 2 ) (
CS0250, Set 3 The master theorem (Ch. 4.3) Let a ≥ 1 and b > 1 be any constants, let f(n) be a function, and let  T(n) be defined on the non-negative integers by the recurrence           T(n) = a T(n/b) + f(n), Then, T(n) can be bounded asymptotically as follows:

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

View Full Document
CS0250, Set 3 The master theorem (Ch. 4.3) Let a ≥ 1 and b > 1 be any constants, let f(n) be a function, and let  T(n) be defined on the non-negative integers by the recurrence            T(n) = a T(n/b) + f(n), Then, T(n) can be bounded asymptotically as follows. 1.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 49

L03 - Divide and Conquer Divide Given some problem divide...

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

View Full Document
Ask a homework question - tutors are online