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