What is Divide and Conquer?
Divide and Conquer splits a problem into smaller subproblems, solves them recursively, and combines results. Unlike DP, subproblems are typically non-overlapping.When to Use
Sorting
Merge Sort, Quick Sort
Searching
Binary Search, finding kth element
Tree Problems
Height, diameter, subtree queries
Array Problems
Maximum subarray, closest pair
The D and C Template
Pattern Variations
1. Merge Sort
2. Quick Sort
3. Maximum Subarray (Kadane Alternative)
4. Binary Tree Maximum Depth
Classic Problems
| Problem | Pattern | Key Insight |
|---|---|---|
| Merge Sort | Classic D and C | Divide array, merge sorted halves |
| Quick Sort | In-place D and C | Partition around pivot |
| Max Subarray | Array D and C | Handle crossing subarray |
| Closest Pair | 2D D and C | Divide plane, check boundary |
| Binary Search | Simple D and C | Eliminate half each time |