1. ABOUT THEALGORITHM
Divide and Conquer Algorithm
Divide and Conquer is an algorithmic technique that
solves complex problems by breaking them into
smaller subproblems, solving them independently,
and combining their solutions.
4.
2. ALGORITHM TARGET
Divideand Conquer Algorithm
Reduce computational complexity.
Take advantage of recursion to break
down and process each part more
efficiently.
Make parallelization easier in big data
processing
5.
3. WHEN WEUSE THIS
ALGORITHM?
The problem can be divided into independent or
nearly independent subproblems.
The subproblems can be solved in a similar way to
the original problem.
The results of the subproblems can be combined
to solve the entire problem.
6.
4. TIME
COMPLEXITY
Let T(n)be the computational
complexity, it is the stopping case.
According to the general algorithm
T(n) = O(1) if n = n0
T(n) = aT(n/b) + D(n) + C(n) nế
u n>no
In there
a: Number of subproblems
n/b: Subproblem size
D(n): Time complexity of the Devide
part
C(n): Time complexity of the Combine
part
5. THE ADVANTAGEAND DISADVANTAGE
OF ALGORITHM.
Overhead
Function Calls: Recursion introduces overhead due to function calls,
which can be significant for problems with a very large number of
recursive calls.
Space Complexity
StackUsage:Recursivealgorithmsmayuseadditionalstackspacepro
portionaltothedepthofrecursion. For instance, Merge Sort uses
0(n) auxiliary space for temporary arrays,
Complexity in Combining Solutions
Merging Subproblems: Combining solutions from subproblems can
be complex and may require additional computational resources.
For example, the merge step in Merge Sort requires merging two
sorted arrays, which is non-trivial.
Base Case Handling
Special Cases: Identifying and handling base cases properly is
crucial. Incorrect base case handling can lead to incorrect results or
infinite recursion.
Efficiency
TimeComplexity:Manyproblemscanbesolvedmoreefficientlyus
ingdivideandconqueralgorithms.
Parallelism
Independent Subproblems: Since subproblems are solved
independently, divide and conquer algorithms can be easily
parallelized. This can lead to significant performance
improvements on multi-core processors or distributed systems.
Simplicity
Problem Decomposition: Breaking down complex problems into
simpler subproblems can make them easier to understand and
solve. This step-by-step approach is often easier to implement
and debug.
Modularity
Reusable Components: Components of the solution can be
reused for different problems. For instance, the merge function
in Merge Sort can be used independently to merge two sorted
arrays.
Advantage Disadvantage
9.
6. PROBLEMS USINGALGORITHMS
The Divide and Conquer algorithm is versatile and can be applied to a wide range of
problems, especially those that can be broken down into smaller, independent
subproblems. Here are some common problems where Divide and Conquer is
particularly effective:
Sorting
Merge Sort
Quick Sort
Searching
Binary Search
Mathematical
Computations
Karatsuba Algorithm
Strassen's Algorithm
Computational
Geometry
Closest Pair of
Points
Convex Hull
Dynamic Programming
Matrix Chain
Multiplication
Longest Common
Subsequence
Optimization Problems
Maximum Subarray
Problem
Median of Medians
Recursion-Based
Problems
Tower of Hanoi
Fibonacci Sequence
Graph Algorithms
Divide and Conquer
for Closest Pair of
Points in 2D
Fast Fourier Transform
(FFT
10.
7. SOLVING REALPROBLEM
Maximum Subarray Sum
Idea:
Divide the array into two halves.
Find the maximum subarray in the left half, the right half, and the maximum subarray
crossing the middle.
Return the maximum of the three.
11.
Merge Sort (Divideand Conquer)
Idea:
Recursively divide the array into
halves.
Sort each half.
Merge the sorted halves