Divide And Conquer.pptx

SHAILIPATEL19 365 views 13 slides Mar 31, 2022
Slide 1
Slide 1 of 13
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13

About This Presentation

In this presentation, I have discussed what divide and conquer is, its advantages, disadvantages and its applications like merge sort, binary search etc.


Slide Content

Divide And Conquer Shaili Patel 18BCE168

What is Divide and Conquer? The problem is divided into smaller subproblems and then each problem is solved independently. The solution of all sub-problems is finally merged in order to obtain the solution of an original problem.

3 steps Divide → breaking the problem into smaller sub-problems. Conquer → smaller subproblems to be solved. Combine → recursively combines them until they formulate a solution of the original problem.

Applications Binary Search Min-Max problem Merge sort Karatsuba’s algorithm

Advantages Solve difficult problems Finding other efficient algorithms Uses memory caches effectively

Disadvantages Recursion is slow The same subproblem can occur many times One must make sure that there is sufficient memory allocated for the recursion stack

Min-Max problem We have to find the minimum and maximum element from the array Approach Divide the list into small groups Find the maximum and minimum of each group The max/min should be one of the max and min of all the groups Time complexity: T(n) = 2T(n/2) + 2 ,n>2 While Non-D&C takes : 2n-2 comparisons D&C takes : 3(n/2) -2 comparisons

Binary Search Implemented on only sorted list of elements The process starts with finding the element at the center of the list and comparing the key value with the element within the middle of the list, if the worth of the key's but the element at the center then the search process the key to the list up to the center element and if the worth of the key's greater than element at the center then search the key from middle element to the top of the list.

Best case - O (1) comparisons : In the best case, the item is the middle of array. . constant no.of comparisons (actually just 1) are required. Worst case - O (log n) comparisons :when the item is not in the array. Through each recursion or iteration of Binary Search, the size of the admissible range is halved. This halving can be done ceiling(log n ) times. Thus, ceiling(log n ) comparisons are required.

Merge Sort Was Invented by John von Neumann (1903-1957) Here, we divide the problem into two halves until all the elements in the subproblems would be sorted . then we start merging the individual sorted array into the final array. Time complexity → O(n log n)

Karatsuba Multiplication Reduces the no.of multiplication Conventional method Karatsuba method

Time complexity : T(n) = 3T(n/2) +O(n) → O(n 1.584 ) Time complexity: O(n 2 ) → conventional method Let's say we want to multiply 1234 & 5678 x H = 12 & x L = 34 y H = 56 & y L = 78 Xy = x H y H * 10 4 + (x H y L + x L y H ) * 10 2 + x L y L 12*56*10 4 + (12*78 +34*56)*10 2 + 34*78 =7006652

Thank you!