0% found this document useful (0 votes)
7 views15 pages

2246 Divide and Conquer Concepts

Uploaded by

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

2246 Divide and Conquer Concepts

Uploaded by

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

Divide and Conquer Concepts

General Method

In divide and conquer approach, a problem is divided into smaller problems, then
the smaller problems are solved independently, and finally the solutions of smaller
problems are combined into a solution for the large problem.

Defective Chessboard

A defective chessboard is a chessboard that has one unavailable (defective)


position. A triomino is an L shaped object that can cover three squares of a
chessboard. A triomino has four orientations.
Binary Search

Binary search looks for a particular item by comparing the middle most item
of the collection. If a match occurs, then the index of item is returned. If the
middle item is greater than the item, then the item is searched in the sub-array to
the left of the middle item.

1. The array in which searching is to be performed is:

2. Set two pointers low and high at the lowest and the highest positions
respectively.

3. Find the middle element mid of the array ie. arr[(low + high)/2] = 6.
4. If x == mid, then return mid.Else, compare the element to be searched with
m.

5. If x > mid, compare x with the middle element of the elements on the right side
of mid. This is done by setting low to low = mid + 1.
6. Else, compare x with the middle element of the elements on the left side of mid.
This is done by setting high to high = mid - 1.
7. Repeat steps 3 to 6 until low meets high.

8.

9. x = 4 found
Max-Min Problem

In this approach, the array is divided into two halves. Then using recursive
approach maximum and minimum numbers in each halves are found. Later, return
the maximum of two maxima of each half and the minimum of two minima of each

half.
Merge Sort

The MergeSort function keeps on splitting an array into two halves until a
condition is met where we try to perform MergeSort on a subarray of size 1, i.e., p
== r. And then, it combines the individually sorted subarrays into larger arrays
until the whole array is merged.
Quick Sort

It is an algorithm of Divide & Conquer type. Divide: Rearrange the elements and
split arrays into two sub-arrays and an element in between search that each element
in left sub array is less than or equal to the average element and each element in the
right sub- array is larger than the middle element.
Selection Sort

Selection sort is an effective and efficient sort algorithm based on comparison


operations. It adds one element in each iteration. You need to select the smallest
element in the array and move it to the beginning of the array by swapping with the front
element.

Strassen’s Matrix Multiplication

Strassen, is an algorithm for matrix multiplication. It is faster than the standard matrix
multiplication algorithm for large matrices, with a better asymptotic complexity, although
the naive algorithm is often better for smaller matrices.

Strassen's Matrix multiplication can be performed only on square matrices where n


is a power of 2. Order of both of the matrices are n × n. Divide X, Y and Z into four
(n/2)×(n/2) matrices as represented below − Z=[IJKL] X=[ABCD] and Y=[EFGH]

You might also like