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

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

View Full Document Right Arrow Icon
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.
Background image of page 1

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

View Full Document Right Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full Document Right Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full Document Right Arrow Icon
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
Background image of page 6
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
Background image of page 7

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

View Full Document Right Arrow Icon
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
Background image of page 8
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
Background image of page 9

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

View Full Document Right Arrow Icon
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
Background image of page 10
CS0250, Set 3 How to merge two sorted lists 5 9 22 67 88 92 12 34 78 98
Background image of page 11

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

View Full Document Right Arrow Icon
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5
Background image of page 12
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5 9
Background image of page 13

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

View Full Document Right Arrow Icon
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5 9 12
Background image of page 14
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5 9 12 22
Background image of page 15

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

View Full Document Right Arrow Icon
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5 9 12 22 34
Background image of page 16
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5 9 12 22 34 67
Background image of page 17

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

View Full Document Right Arrow Icon
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5 9 12 22 34 67 78
Background image of page 18
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5 9 12 22 34 67 78 88
Background image of page 19

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

View Full Document Right Arrow Icon
CS0250, Set 3 5 9 22 67 88 92 12 34 78 98 5 9 12 22 34 67 78 88 92
Background image of page 20
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.
Background image of page 21

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

View Full Document Right Arrow Icon
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 ) (
Background image of page 22
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:
Background image of page 23

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

View Full Document Right Arrow Icon
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.
Background image of page 24
Image of page 25
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 Right Arrow Icon
Ask a homework question - tutors are online