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

DIVIDE and CONQUER ALGORITHM Another common technique used to design algorithms is divide and conquer.

This is a technique for designing algorithms that consists of decomposing the instances to be solved into a number of smaller subinstances of the dame problem, solving successively and independently each of these subinstances, and then combining the subsolutions thus obtained to obtain the solution of the original instance. Traditionally, algorithms in which the text contains at least two recursive calls are called divide and conquer algorithm, while algorithm whose text contains only one recursive call are not. The algorithm will first check to see of the problem size is small enough to determine a solution by some simple non recursive algorithm called here adhoc ; and if so, will do that. If the problem is too large, it will first decompose the input into number smaller sets of input values. These smaller set may all be of the same size. Each of these smaller sets will have fewer elements than the original input set. The Divide-and-Conquer algorithm is then called recursively for each of these smaller input sets and the result from those calls is recombined together. Divide and conquer algorithm consist of two parts: 1. Divide or Decompose: The given problem is decomposed into smaller problems of similar size recursively. 2. Conquer or Recombine: The solution to the original problem is then formed from the solutions to the subproblem. The general template for divide-and-conquer algorithms is as follows :
function DC(x) if ( x is sufficiently small or simple ) then return adhoc(x) decompose x into smaller instances x1, x2, x3.xl for i yi return y 1 to l do DC(xi)

recombine the yis to obtain a solution for x

Here, adhoc is a simple algorithm capable of solving the problem on small instances, but its performance on large instances is of no concern. We call it the basic subalgorithm. The number of subinstances , l is usually small and independent of the particular instance to be solved. For divide and conquer to be worthwhile three conditions must be met : Amrita Vishwa Vidypeethem Kavitha K R

1. The decision when to use the basic subalgorithm, rather then to make recursive calls. 2. It must be possible to decompose an instance into subinstances and to recombine the subsolutions efficiently 3. Subinstances should as far as possible be of about the same seze. Most divide and conquer algorithms are such that the size of the l subinstances is roughly n/b for some constant b, where n is the size of the original and b is a constant. The running time analysis of such divide and conquer algorithm are almost automatic Let g(n) be the time required by DC on instance Is size n, not counting the time needed for the recursive calls. The total time t(n) taken by this divide and conquer algorithm is something like : T(n) = lT(n b) + g(n) If there exists an integer k such that g(n) = (nk) then (nk) , T(n) = (nk log n) (nlog l) if l < bk if l = bk if l>bk

It remains to see how to determine whether to divide the instance and make recursive calls, or whether the instance is so simple that it is better to invoke the basic subalgorithm directly. With most divide-and-conquer algorithms, this decision is based on a simple threshold, usually denoted no. The basic subalgorithm is used to solve any instance whose size does not exceed no.

Amrita Vishwa Vidypeethem Kavitha K R

You might also like