lecture15DivAndConquerDesign3

lecture15DivAndConquerDesign3 - Divide and Conquer Divide:...

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

View Full Document Right Arrow Icon
1 Divide and Conquer Divide : Divide the problem into smaller subproblems Solve the subproblems recursively. If subproblem is small enough, solve it in a straightforward manner (base case) Conquer : Combine the solution of the subproblems into the solution for the original problem. The subproblems should not overlap.
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Divide and Conquer Examples Binary Search Heap Construction Tower of Hanoi Quick Sort Merge Sort Multiplying large Integers Exponentiation Matrix Multiplication (Strassen’s way)
Background image of page 2
3 Exponentiation long Power ( int x, int n) { if (n==0) return 1; else { y = Power (x, n/2); if (n % 2 == 0) return (y*y) // n even else return (y*y*x); }
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Heap Construction Construct heap of T => Construct heap T1, Construct heap T2 Adjust heap with root T T T1 T2
Background image of page 4
5 8 3 4 1 6 5 2 7 8 3 4 1 6 5 2 7 1 2 3 4 5 6 7 8 1 3 4 8 2 5 6 7 Merge Sort
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Running time for Divide and Conquer Merge sort: T(N)=2T(N/2)+O(N) We showed this to be: O(NlogN) Is there a more general way to solve these? 2 subproblems Subproblem size Cost of combining subproblems
Background image of page 6
7 The Master Theorem The solution to the equation T(N)=aT(N/b) +O(N k ), where a 1 and b>1 is: 1 1 1 1 1 < = = k k k k k a b a if b a if b a if N O N N O N O N T b ) ( ) log ( ) ( ) ( log
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Solving… T(N)=2T(N/2)+O(N) a=2 b=2 k=1 1 1 1 1 1 < = = + = k k k k k a k b a if b a if b a if N O N N O N O N T N O b N aT N T b ) ( ) log ( ) ( ) ( ) ( ) / ( ) ( log
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.

Page1 / 32

lecture15DivAndConquerDesign3 - Divide and Conquer Divide:...

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