lecture15DivAndConquerDesign3

lecture15DivAndConquerDesign3 - Divide and Conquer Divide...

Info icon This 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.
Image of page 1

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

View Full Document Right 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)
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); }
Image of page 3

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

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

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

View Full Document Right 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
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
Image of page 7

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern