Back to Academy
patterns
Divide and Conquer
Divide and conquer breaks a problem into smaller, independent subproblems of the same type, solves each recursively, and combines the results. Classic examples include merge sort and binary search. The key insight is that combining solutions to subproblems is often more efficient than solving the original problem directly.
Use Cases
- •Merge sort and quicksort algorithms
- •Finding the closest pair of points in a plane
- •Computing large exponents efficiently with fast power
Complexity Analysis
| Metric | Best | Average | Worst |
|---|---|---|---|
| Time | O(n log n) | O(n log n) | O(n log n) |
| Space | O(n) | ||
Visualization
Implementation
Output
Click "Run Code" to see output...