This is a very important type of algorithm paradigm which is mostly used to solve any kind of problems like sorting ( merge sort, quick sort), binary search, Tower of Hanoi, etc.
3. Divide and Conquer
It is an algorithm design paradigm which is based on
multi branch recursion.
The divide-and-conquer paradigm is often used to find
an optimal solution to a problem.
It is a technique to break a problem recursively into
sub-problems of the same or related type.
Sub-programs have to be simple enough to be solved
directly.
The solutions to these sub-problems are then
combined to solve the original problem
4. Divide and Conquer
D&C follow following three steps
Divide/Break- Break original problem into sub-
problems
Conquer/Solve - Solve every individual sub-problem,
recursively
Combine/Merge- Place the solutions to the sub-
problems together to solve the entire problem
5. Divide and Conquer
In short, D&C is a approach in which the entire
problem (i.e. too large to comprehend or overcome at
once) is divided into smaller pieces, the pieces are
solved separately, and all the pieces are combined
together.
7. Implementation
Program to calculate pow(x,n) in C language
#include<stdio.h>
#include<conio.h>
/* Function to calculate x raised to the power y */
int power(int x, unsigned int y)
{
if (y == 0)
return 1;
else if (y%2 == 0)
return power(x, y/2)*power(x, y/2);
9. Application
Following computer algorithms are based on divide
and conquer programming approach
Bineary Search
Merge Sort
Quick Sort
Maximum and Minimum Problem
Tower of Hanoi
Strassen's Matrix multiplication
Karatsuba Algorithm
10. 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 sub-problems in the recursion
n/b = size of each sub-problem. All sub-problems 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
11. Advantages
The complexity for the multiplication of two matrices
using the naive method is O(n3), whereas using the
divide and conquer approach (ie. Strassen's matrix
multiplication) is O(n2.8074).
This strategy also simplifies other issues such as the
Tower of Hanoi.
Suitable for multiprocessing systems.
It does use memory caches effectively.