0% found this document useful (0 votes)
31 views12 pages

Decrease and Conquer

The document discusses the decrease-and-conquer technique, which exploits the relationship between solutions to problem instances of different sizes. It can be applied top-down or bottom-up. Variations include decreasing the instance size by a constant or constant factor on each iteration, or with a variable decrease. Insertion sort is provided as an example of decreasing by one element on each pass to sort an array.

Uploaded by

Joe Cands
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)
31 views12 pages

Decrease and Conquer

The document discusses the decrease-and-conquer technique, which exploits the relationship between solutions to problem instances of different sizes. It can be applied top-down or bottom-up. Variations include decreasing the instance size by a constant or constant factor on each iteration, or with a variable decrease. Insertion sort is provided as an example of decreasing by one element on each pass to sort an array.

Uploaded by

Joe Cands
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/ 12

DECREASE AND CONQUER

JOSE Q. CANDIA, JR.


DEFINITION

• The decrease-and-conquer technique is based on exploiting the relationship between a solution to a given instance of
a problem and a solution to its smaller instance.

• Can be exploited either top down or bottom up.

• Top down naturally leads to a recursive implementation

• Bottom up usually implemented iteratively, starting with a solution to the smallest instance of the problem.
Decrease by a constant Decrease by a constant Variable size decrease
factor

VARIATIONS OF DECREASE AND CONQUER


DECREASE BY A CONSTANT

• The size of the instance is reduced by the same constant on each iteration of the algorithm

• This constant is typically equal to 1.

• Top down naturally leads to a recursive implementation

• Bottom up usually implemented iteratively, starting with a solution to the smallest instance of the problem.
DEFINITION
DECREASE BY A CONSTANT FACTOR

• This technique suggests reducing a problem instance by the same constant factor on each iteration of the algorithm.

• This constant is typically equal to 2.


DEFINITION
THE VARIABLE-SIZE DECREASE

• The size-reduction pattern varies from one iteration of an algorithm to another.


• Euclid’s algorithm for computing the greatest common divisor provides a good example.
gcd(m,n) = gcd(n, m mod n)
INSERTION SORT

• An application of the decrease by-one technique to sorting an array.


• We assume that the smaller problem of sorting the array A[0..n-2] has already been solved to give us a sorted array of
size n – 1.
• All we need is to find an appropriate position for A[n-1] among the sorted elements and insert it there.
• This is usually done by scanning the sorted subarray from right to left until the first element smaller than or equal to
A[n-1] is encountered to insert A[n-1] right after that element.
• The algorithm sorts the input numbers in place; it rearranges the number within the array A with at most a constant
number of them stored outside the array at any time.
INSERTION SORT

• Algorithm
• //Input: An array A[0..n-1] of n orderable elements
• //Output: Array A[0..n-1] sorted in nondecreasing order
• For I = 1 to n – 1 do
DIGITAL COMMUNICATIONS

Cloud

Local

Hybrid
THANK YOU
[email protected]

You might also like