You are on page 1of 10

Design & Analysis of Algorithm

PCC-CS494

Recurrence Equation and its solution

IT (A) - 2nd year - 4th sem

 GROUP NUMBER -14


 MEMBER ‘S NAME:
Shuvadeep Masanta 13000219047
Saroj Kumari 13000219048
Vicky Kumar 13000219049
What is Recurrence Relation?
A recurrence is an equation or inequality that describes a function in terms of its values on smaller inputs.
To solve a Recurrence Relation means to obtain a function defined on the natural numbers that satisfy the
recurrence.

To solve a recurrence equation basically there are 4 methods:

1.Substitution Method

2.Recursion Tree Method

3.Master Method

4.Iteration Method
Substitution method:
•The most general method:
•Guess the form of the solution.
•Verify by induction.
•Solve for constants.
•Example: T(n) = 4T(n/2) + 100n
•[Assume that T(1) = Q(1).]
•Guess O(n3) . (Prove O and W separately.)
•Assume that T(k) £ ck3 for k < n .
•Prove T(n) £ cn3 by induction.
•We must also handle the initial conditions, that is, ground the induction with base cases.
•Base: T(n) = Q(1) for all n < n0, where n0 is a suitable constant.
•For 1 £ n < n0, we have “Q(1)” £ cn3, if we pick c big enough.
Recursion-tree method:

 A recursion tree models the costs (time) of a recursive


execution of an algorithm.
 The recursion tree method is good for generating guesses
for the substitution method.
 The recursion-tree method can be unreliable, just like any
method that uses ellipses (…).
 The recursion-tree method promotes intuition, however .

L2.4
Example of recursion tree:
Solve T(n) = T(n/4) + T(n/2) + n2:

T(n)  n2 n2

T(n/4) T(n/2) (n/4)2 (n/2)2

T(n/16) T(n/8) T(n/8) T(n/4)


Example of recursion tree:
Solve T(n) = T(n/4) + T(n/2) + n2:
n2 ---------------------------------------------- n2
(n/4)2 (n/2)2 -----------------------------------------(5/16)n2

(n/16)2 (n/8)2 (n/8)2 (n/4)2 -----------------------------------(25/256)n2


| | | | |

| | | | |

| | | | |

Q(1) Total =n2 (1+(5/16)+(5/16)2 +(5/16)3+…………………..)


= Q(n2 )
MASTER METHOD:
 The Master Method is used for solving the following types of recurrence

 T(n) = aT(n/b) + f(n)


where,
 n = size of input

 a = number of subproblems in the recursion

 n/b = size of each subproblem. All subproblems are assumed

to have the same size.


 f(n) = cost of the work done outside the recursive call,

which includes the cost of dividing the problem and


cost of merging the solutions
 
Here, a ≥ 1 and b > 1 are constants, and f(n) is an asymptotically positive function.
THREE COMMON CASES:
 CASE 1- If f(n)<nlogba Then T(n) = Q(nlogba)
 CASE 2- If f(n)=nlogba Then T(n) = Q (nlogba lgk+1n)
 CASE 3- If f(n)>nlogba Then T(n) = Q(f(n))
 EXAMPLE:
 Ex. T(n) = 4T(n/2) + n

a = 4, b = 2  nlogba = n2; f (n) = n.


CASE 1: f (n) = O(n2 – e) for e = 1.
 T(n) = Q(n2).

 Ex. T(n) = 4T(n/2) + n2

a = 4, b = 2  nlogba = n2; f (n) = n2.


CASE 2: f (n) = Q(n2lg0n), that is, k = 0.
 T(n) = Q(n2lg n).
EXAMPLE CONTINUED….

 Ex. T(n) = 4T(n/2) + n3

a = 4, b = 2  nlogba = n2; f (n) = n3.


CASE 3: f (n) = W(n2 + e) for e = 1
and 4(cn/2)3 £ cn3 (reg. cond.) for c = 1/2.
 T(n) = Q(n3).

 Ex. T (n) = 0.5T (n/2) + 1/n

Master method does not apply, as a<1.


THANK YOU

You might also like