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

yebob31798 yebob (4)

yebob31798 is a passionate content creator who specialises in writing practical, SEO-friendly articles for home improvement and air conditioning services. With a strong focus on clarity and value, they craft helpful guides that connect homeowners wit

ac aircon (4)

Beat the heat year-round with LetsCool Aircon, Singapore go-to specialist for all your cooling needs. With decades of proven expertise, we offer top-notch aircon installation, aircon servicing, and repairs for both homes and businesses.

litol35986 lit (3)

litol35986 is a passionate writer who creates clear, engaging content across home improvement and aircon care topics. With a focus on helpful tips and practical insights, they aim to educate readers and simplify everyday decisions. Their work combine

Latest Articles