The Divide-and-Conquer strategy suggests splitting the n inputs into 'k' distinct subsets, yielding 'k' sub problems. If the sub problems are still relatively large, then the divide-and-conquer strategy can possibly be reapplied. These sub problems must be solved, and then a method must be found to combine sub solutions into a solution of the whole.
i) Divided into smaller subproblems.
ii) These subproblems are solved independently.
iii) Combining all the solutions of subproblems into a solution of the whole.
If the sub problems are still relatively large, then divide-and-conquer is reapplied. The generated sub problems are usually of same type as the original problem. Hence recursive algorithm are used.
Algorithm:Algorithm DAndC(P)
{
if small(P) then
return S(P);
else
{
divide P into smaller instances
P1, P2 .. Pk, k>=1;
Apply DAndC to each of these sub problems;
return combine (DAndC(P1), DAndC(P2),...,DAndC(Pk));
}
}
The computing time of above procedure of divide and conquer is given by the recurrence relation.
Where T(n) is the time for divide and conquer of size n. The g(n) is the computing time required to solve small inputs. The F(n) is the time required in dividing problem P and combining the solution to sub problems.
The complexity of many divide-and-conquer algorithms is given by recurences of the form
Consider the case in which a=2 and b=2. Let T(n)=2 and f(n)=n. we have
In general, we see that
, for any
in particular, corresponding to the choice of
Thus,