Lecture 4 Divide-and-Conquer
What’s Self-Reducibility? A problem can be reduced to several “same” problems with smaller inputs.
Divide and Conquer Divide the problem into subproblems. Conquer the subproblems by solving them recursively. Combine the solutions to subproblems into the solution for original problem.
Tree Structure problem subproblem subproblem subsubproblem
Insertion Sort
key
Merge Sort
Procedure divide conquer combine
Heapsort 16 14 10 3 8 7 9 2 4 1
Heapsort
Heapsort
Quicksort divide conquer combine is simplified
Selection with O(n) Comparisons divide conquer divide conquer
Remark on Divide and Conquer Key Point:
Merge Sort Quick Sort Selection Analysis requires to solve a recurrence!
Maximum Subarray
Problem
Closest pair of points
Matrix Multiplication
n/2 Step 1 n/2
Step 2 Step 3
Step 4
Master Theorem