3. DEFINITION:
The divide-and-conquer rule consists in breaking a
problem into simpler sub-problems of the same
type, next to solve these sub-problems, finally to
merge the obtained results into a solution to the
problem.
4. Divide and conquer technique is used for sorting the
elements of array in some specific order.
5. Dividing the main problem into smaller ones.
These smaller sub-problems are divided further.
Recombine them to achieve the main objective.
6. Let’ see few analysis to confirm the usefulness of the divide and conquer
technique.
To sort the one major problem time is nlog(n)2
To sort the halves approximate time is (n/2) 2+(n/2) 2
To merge the two halves approximate time is n
So, for n=100, divide and conquer takes approximately:
= (100/2) 2 + (100/2) 2 + 100
= 2500 + 2500 + 100
= 5100
Suppose that n is 100. Considering if we apply insertion sort algorithm on it then
the
time taken will be approximately (100) 2 n = 10000. Now, if we apply divide and
conquer technique on it. Then for first half approximate time will be (100/2) 2.
Similarly for second half it will be (100/2) 2. The merging approximate time will
be 100. So the whole operation of sorting using this divide and conquer
technique in insertion sort will take around (100/2) 2 + (100/2)2+100 = 5100.
Clearly the time spent (5100) after applying divide and conquer mechanism is
significantly lesser than
the previous time (10000).
7. WORKING:
subproblem 2
of size n/2
subproblem 1
of size n/2
a solution to
subproblem 1
a solution to
the original problem
a solution to
subproblem 2
a problem of size n