Technology > AI

Divide and conquer algorithm explained

Divide and Conquer is an algorithmic paradigm (sometimes mistakenly called "Divide and Concur" - a funny and apt name), similar to Greedy and Dynamic Programming. A typical Divide and Conquer algorithm solves a problem using the following three steps.

1. Divide: This involves dividing the problem into some sub problem.

2. Conquer: Sub problem by calling recursively until sub problem solved.

3. Combine: The Sub problem Solved so that we will get find problem solution. 

The following are some standard algorithms that follows Divide and Conquer algorithm.  

Quicksort is a sorting algorithm. The algorithm picks a pivot element, rearranges the array elements in such a way that all elements smaller than the picked pivot element move to left side of pivot, and all greater elements move to right side. Finally, the algorithm recursively sorts the subarrays on left and right of pivot element.

Merge Sort is also a sorting algorithm. The algorithm divides the array in two halves, recursively sorts them and finally merges the two sorted halves.

Closest Pair of Points The problem is to find the closest pair of points in a set of points in x-y plane. The problem can be solved in O(n^2) time by calculating distances of every pair of points and comparing the distances to find the minimum. The Divide and Conquer algorithm solves the problem in O(nLogn) time.

Strassen’s Algorithm is an efficient algorithm to multiply two matrices. A simple method to multiply two matrices need 3 nested loops and is O(n^3). Strassen’s algorithm multiplies two matrices in O(n^2.8974) time.

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(nlogn) time.

Karatsuba algorithm for fast multiplication it does 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.

Divide And Conquer algorithm :  

DAC(a, i, j)

{

    if(small(a, i, j))

      return(Solution(a, i, j))

    else 

      m = divide(a, i, j)               // f1(n)

      b = DAC(a, i, mid)                 // T(n/2)

      c = DAC(a, mid+1, j)            // T(n/2)

      d = combine(b, c)                 // f2(n)

   return(d)

}

Recurrence Relation for DAC algorithm : 

This is recurrence relation for above program. 

           O(1) if n is small

T(n) =     f1(n) + 2T(n/2) + f2(n)


Example: 

To find the maximum and minimum element in a given array. 

Input: { 70, 250, 50, 80, 140, 12, 14 }

Output: The minimum number in a given array is : 12

The maximum number in a given array is : 250

Monica Planas

author

I am Professional Writer and Web Designer. I love to write articles.

Article comments

Leave a Reply

Popular Authors

Aaryan Rana (3)

I am an experienced digital marketing analyst with a passion for data-driven insights, optimizing campaigns, and driving business growth with 3years exp.

Anvi Apte (2)

Anvi Apte is a marketing research manager at Novus Insights, a leading research and analytics services company.

Avneet Singh (2)

I love traveling and exploring new places. As an SEO Executive at Brevistay, I am working to improve the online presence and website ranking of Brevistay.

Latest Articles