Algorithm Design Techniques - 1556432967209
Algorithm Design Techniques - 1556432967209
Techniques
Instructor: Faisal Anwer, DCS, AMU
SOURCE:
Introduction to Algorithm (3rd Edition) by Thomas H. Cormen, Charles E.
Leiserson, Ronald L. Rivest, Clifford Stein + Freely Accessible Web Resources
ALGORITHM DESIGN TECHNIQUES
recursively.
Combine: The solutions are combined to the sub problems
into the solution for the original problem.
.
ANALYSIS OF DIVIDE-AND-CONQUER
Running time of a divide-and-conquer algorithm are
calculated from the three steps of the basic paradigm.
Let T(n) be the running time on a problem of size n, If the
problem size is small enough, say n for some constant c, the
straightforward solution takes constant time, which we write
as Ɵ(1).
Suppose that our division of the problem yields a
subproblems, each of which is 1/b the size of the original. So
the time would be a.T(n/b) to solve a subproblems.
If we take D(n) time to divide the problem into subproblems
and C(n) time to combine the solutions to the subproblems
into the solution to the original problem, then the total time :
.
• Divide: The divide step just computes the middle of the
subarray, which takes constant time. Thus, D(n)=Ɵ(1).
• Conquer: We recursively solve two subproblems, each of
size n/2, which contributes 2T(n/2) to the running time.
• Combine: MERGE procedure on an n-element subarray
takes time Ɵ(n), and so C(n)=Ɵ(n).