0% found this document useful (0 votes)
10 views109 pages

DAA Module-2-1

Uploaded by

Suurya KS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views109 pages

DAA Module-2-1

Uploaded by

Suurya KS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 109

Module-2

Divide and Conquer


Using Divide And Conquer approach, the problem in hand, is divided into smaller
sub-problems and then each problem is solved independently.

When we keep dividing the sub-problems into even smaller sub-problems, we may
eventually reach a stage where no more division is possible.

Those smallest possible sub-problems are solved using original solution because it
takes lesser time to compute.

The solution of all sub-problems is finally merged in order to obtain the solution of
the original problem.
Broadly, we can understand divide-and-conquer approach in a three-step process.

Divide/Break
This step involves breaking the problem into smaller sub-problems. Sub-problems should
represent a part of the original problem. This step generally takes a recursive approach to
divide the problem until no sub-problem is further divisible. At this stage, sub-problems
become atomic in size but still represent some part of the actual problem.

Conquer/Solve
This step receives a lot of smaller sub-problems to be solved. Generally, at this level, the
problems are considered 'solved' on their own.

Merge/Combine
When the smaller sub-problems are solved, this stage recursively combines them until
they formulate a solution of the original problem. This algorithmic approach works
recursively and conquer & merge steps works so close that they appear as one.
Advantages of Divide and Conquer
 Divide and Conquer tend to successfully solve one of the biggest problems, such as the Tower of
Hanoi, a mathematical puzzle. It is challenging to solve complicated problems for which you
have no basic idea, but with the help of the divide and conquer approach, it has lessened the
effort as it works on dividing the main problem into two halves and then solve them recursively.
This algorithm is much faster than other algorithms.

 It efficiently uses cache memory without occupying much space because it solves simple
subproblems within the cache memory instead of accessing the slower main memory.

 It is more proficient than that of its counterpart Brute Force technique.

 Since these algorithms inhibit parallelism, it does not involve any modification and is handled
by systems incorporating parallel processing.
Disadvantages of Divide and Conquer
•Since most of its algorithms are designed by incorporating recursion, so it
necessitates high memory management.

•It may even crash the system if the recursion is performed rigorously greater than
the stack present in the CPU.
Solving Recurrence Relations

Recurrence relations can be solved using multiple methods; they are −

 Recurrence Tree Method

 Substitution Method

 Iteration Method

 Master Theorem
Recurrence Relation
Recurrence Relations
Recurrence Relation
No of times
Substitution Method
MASTER THEOREM
• The master theorem is used in calculating the time complexity of
recurrence relations (divide and conquer algorithms & Decrease
and Conquer) in a simple and quick way.
Dividing Functions
STRASSEN ALGORITHM
• In linear algebra, the Strassen algorithm, named after Volker
Strassen, is an algorithm for matrix multiplication. It is faster than
the standard matrix multiplication algorithm for large matrices,
with a better asymptotic complexity
STRASSEN ALGORITHM FOR MATRIX
MULTIPLICATION (DIVIDE AND CONQUER)
Topology: the way in which constituent parts are interrelated or arranged.
// Insertion sort in C // Driver code
#include <stdio.h> int main() {
int data[] = {9, 5, 1, 4, 3};
void insertionSort(int array[], int size) { int size = sizeof(data) /
for (int step = 1; step < size; step++) { sizeof(data[0]);
int key = array[step]; insertionSort(data, size);
int j = step - 1; printf("Sorted array in ascending
// Compare key with each element on the left of it until order:\n");
an element smaller than printArray(data, size);
// it is found. For descending order, change key<array[j] }
to key>array[j].
while (key < array[j] && j >= 0) {
array[j + 1] = array[j]; // Function to print an array
j=j-1; void printArray(int array[], int size)
} {
array[j + 1] = key; for (int i = 0; i < size; i++) {
} printf("%d ", array[i]);
} }
printf("\n");
}

You might also like