Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Full name: Rohit Manna

Roll no: 19458122005

Registration No: 221941810004

Stream: M.SC (Data Analytics)

Semester: 3rd

Paper Name: Design and Analysis of Algorithm

Paper Code: MDS-304


What is Divide and Conquer?
Divide and Conquer is an algorithmic paradigm in which the problem is solved using the
Divide, Conquer, and Combine strategy.

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.

Standard algorithms that follow Divide and Conquer algorithm


The following are some standard algorithms that follow Divide and Conquer algorithm.
1. Quicksort is a sorting algorithm. The algorithm picks a pivot element and
rearranges the array elements so that all elements smaller than the picked
pivot element move to the left side of the pivot, and all greater elements
move to the right side. Finally, the algorithm recursively sorts the subarrays
on the left and right of the pivot element.
2. Merge Sort is also a sorting algorithm. The algorithm divides the array into
two halves, recursively sorts them, and finally merges the two sorted
halves.
3. Closest Pair of Points The problem is to find the closest pair of points in a
set of points in the x-y plane. The problem can be solved in O(n^2) time by
calculating the distances of every pair of points and comparing the
distances to find the minimum. The Divide and Conquer algorithm solves
the problem in O(N log N) time.
4. Strassen’s Algorithm is an efficient algorithm to multiply two matrices. A
simple method to multiply two matrices needs 3 nested loops and is
O(n^3). Strassen’s algorithm multiplies two matrices in O(n^2.8974) time.
5. Cooley–Tukey Fast Fourier Transform (FFT) algorithm is the most
common algorithm for FFT. It is a divide and conquer algorithm which
works in O(N log N) time.
6. Karatsuba algorithm for fast multiplication does the multiplication of
two n-digit numbers in at most single-digit multiplications in general (and
exactly when n is a power of 2). It is, therefore, faster than
the classical algorithm, which requires n2 single-digit products. If n = 210 =
1024, in particular, the exact counts are 310 = 59, 049 and (210)2 = 1, 048,
576, respectively.
Example of Divide and Conquer algorithm

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.

T(n) = aT(n/b) + f(n),

where,

n = size of input

a = number of subproblems in the recursion


n/b = size of each subproblem. All subproblems are assumed to have the same size.

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

Let us take an example to find the time complexity of a recursive problem.

For a merge sort, the equation can be written as:

T(n) = aT(n/b) + f(n)

= 2T(n/2) + O(n)

Where,

a = 2 (each time, a problem is divided into 2 subproblems)

n/b = n/2 (size of each sub problem is half of the input)

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.)

Now, T(n) = 2T(n log n) + O(n)

≈ O(n log n)

Advantages of Divide and Conquer Algorithm


• The complexity for the multiplication of two matrices using the naive
method is O(n3) , whereas using the divide and conquer approach (i.e.
Strassen's matrix multiplication) is O(n2.8074) . This approach also
simplifies other problems, such as the Tower of Hanoi.
• This approach is suitable for multiprocessing systems.

• It makes efficient use of memory caches.


Disadvantages of Divide and Conquer Algorithm

• It can be difficult to find the base case for the recursion.

• It can require a lot of stack space, especially for problems with deep

recursion.

• It can be sensitive to the order in which the subproblems are solved.

Divide and Conquer Applications


• Binary Search
• Merge Sort
• Quick Sort
• Strassen's Matrix multiplication

• Karatsuba Algorithm

THE END

You might also like