lecture15DivAndConquerDesign3

# lecture15DivAndConquerDesign3 - Divide and Conquer Divide...

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

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.

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

View Full Document
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)
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); }

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

View Full Document
4 Heap Construction Construct heap of T => Construct heap T1, Construct heap T2 Adjust heap with root T T T1 T2
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

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

View Full Document
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
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

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

View Full Document
8 Solving… T(N)=2T(N/2)+O(N) a=2 b=2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern