Professional Documents
Culture Documents
Rohit Manna SEM3 CA2 MSD304 MSC (DA)
Rohit Manna SEM3 CA2 MSD304 MSC (DA)
Semester: 3rd
A typical Divide and Conquer algorithm solves a problem using following three steps:
1. Divide: This involves dividing the problem into smaller sub-problems.
2. Conquer: Solve sub-problems by calling recursively until solved.
3. Combine: Combine the sub-problems to get the final solution of the whole
problem.
A classic example of Divide and Conquer is Merge Sort demonstrated below. In Merge
Sort, we divide array into two halves, sort the two halves recursively, and then merge the
sorted halves.
Time Complexity
The complexity of the divide and conquer algorithm is calculated using
the master theorem.
where,
n = size of input
f(n) = cost of the work done outside the recursive call, which includes the cost of
dividing the problem and cost of merging the solutions
= 2T(n/2) + O(n)
Where,
f(n) = time taken to divide the problem and merging the subproblems
T(n/2) = O(n log n) (To understand this, please refer to the master theorem.)
≈ O(n log n)
• It can require a lot of stack space, especially for problems with deep
recursion.
• Karatsuba Algorithm
THE END