0% found this document useful (0 votes)
14 views16 pages

CSPC24 Chapter 6 - Decrease and Conquer Algorithm Design Technique

The document outlines the decrease-and-conquer algorithm design technique, which involves solving a problem by reducing it to smaller instances. It describes the two implementation approaches (top-down and bottom-up) and identifies three variations: decrease by a constant, decrease by a constant factor, and variable size decrease. Examples of algorithms utilizing this technique include insertion sort, binary search, and Euclid's algorithm.
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)
14 views16 pages

CSPC24 Chapter 6 - Decrease and Conquer Algorithm Design Technique

The document outlines the decrease-and-conquer algorithm design technique, which involves solving a problem by reducing it to smaller instances. It describes the two implementation approaches (top-down and bottom-up) and identifies three variations: decrease by a constant, decrease by a constant factor, and variable size decrease. Examples of algorithms utilizing this technique include insertion sort, binary search, and Euclid's algorithm.
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/ 16

CSPC 24

Algorithm and
Complexity
DECREASE AND CONQUER
ALGORITHM DESIGN TECHNIQUE
Objectives
• Define and identify decrease-and-conquer algorithm
design technique.

• Synthesize the application of decrease-and-conquer


algorithm design technique to problem solving.

• Apply the different variations of decrease-and-conquer


algorithm design technique
DECREASE-AND-CONQUER ALGORITHM
DESIGN TECHNIQUE
• a general algorithm design strategy based on exploiting
the relationship between a solution to a given instance
of a problem and a solution to a smaller instance of the
same problem.

• The exploitation can be either top-down (recursive) or


bottom-up (nonrecursive).
Implementations of Decrease and
Conquer
This approach can be either implemented as top-down or
bottom-up.

• Top-down approach : It always leads to the recursive


implementation of the problem.

• Bottom-up approach : It is usually implemented in


iterative way, starting with a solution to the smallest
instance of the problem.
Variations of Decrease and Conquer
There are three major variations of decrease-and-
conquer:

• Decrease by a constant

• Decrease by a constant factor

• Variable size decrease


Examples of Decrease-and-Conquer
Algorithms
Decrease by one:
• Insertion sort
• Graph search algorithms:
• DFS
• BFS
• Topological sorting
• Algorithms for generating permutations, subsets
Examples of Decrease-and-Conquer
Algorithms
Decrease by a constant factor:

• Binary search

• Fake-coin problems

• Multiplication à la russe

• Josephus problem
Examples of Decrease-and-Conquer
Algorithms
Variable-size decrease:

• Euclid’s algorithm
• Selection by partition
Examples of Decrease-and-Conquer
Algorithms

The decrease-by-a-constant-factor technique suggests


reducing a problem instance by the same constant factor
on each iteration of the algorithm. In most applications,
this constant factor is equal to two.
Decrease by One: Insertion Sort
Insertion Sort

Algorithm to sort n elements:


o Sort n-1 elements of the array
o Insert the n-th element

Complexity: Θ(n2) in the worst and the average case, and


Θ(n) on almost sorted arrays.
Decrease by One: Insertion Sort
Insertion Sort
for i ← to n-1 do // move the unsorted portion
v ← A[i] // value to sort
j ← i-1 // end of the sorted array
while j ≥ 0 and A[j] > v do // scan the sorted part of the array for
the
insertion point
A[j+1] ← A[j] // shift the sort array to make room for the insertion
j--
A[j+1] ← v // insert
Decrease by One: Graph Search
Depth-first search algorithm:
dfs(v)
process(v)
mark v as visited
for all vertices i adjacent to v not visited
dfs(i)
Decrease by One: Graph Search
Depth-first search:
Decrease by One: Graph Search
Breadth-first search algorithm:
procedure bfs(v)
q := make_queue()
enqueue(q,v)
mark v as visited
while q is not empty
v = dequeue(q)
process v
for all unvisited vertices v' adjacent to v
mark v' as visited
enqueue(q,v')
Directed Graphs and
Topological Sorting
Directed Graph:
Directed graphs, di-graph, have edges with
directions, arrows. In real life the directed edges can
represent dependencies.

Topological Sort:
Topological sort is an ordering of the vertices that is
not contrary to the dependencies. In other words, if you
were to perform one job at a time, a topological sort is
one order that you could perform the jobs.
Thank you!
REFERENCES:
Cormen T., Leiserson C., Rivest R., & Stein C. (2009). Introduction to Algorithms Third
Edition. The MIT Press, Cambridge, Massachusets
Fleck, Margaret M., (2013). Building Blocks for Theoretical Computer Science. Version
1.3 (January 2013)
Lehman, Eric F., Leighton, Thomson & Meyer, Albert R. (2018). Mathematics for
Computer Science. June 2018
ONLINE REFERENCES:
https://www.geeksforgeeks.org/
http://www.freebookcentre.net/CompuScience/free-computer-algorithm-books.html

You might also like