0% found this document useful (0 votes)
27 views2 pages

02 Recurrence Relations

solving rr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views2 pages

02 Recurrence Relations

solving rr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

RECURRENCE RELATIONS

Recurrence relation solving:

1). Substitution method

2). Recursive tree method

3). Master’s theorem

Substitution method:

Substituting given function repeatedly until given function is removed.

Time complexity depends on input size.

For input size ‘n’ time taken is T(n)

In T(n) what activities are performed

Eg 1:

T(n) = { 1 if n=0

{ T(n-1) +1 if n>0

Sol:

T(n) = T(n-1) + 1

T(n) = [ T(n-2) +1 ] +1

T(n) = T(n-2) +2

T(n) = [T(n-3) +1 ] +2

T(n)=T(n-3)+3

T(n) =T(n-k) +k

(n-k) =0=> n=k

T(n) = T(0) +n

T(n) = 1+n= O(n)


Eg 2:

T(n) = T(n-1) + n n>0

T(0) =1

Sol:

T(n)=T(n-1) + n

T(n) =[T(n-2) + (n-1) ] + n

T(n) = T(n-2) + (n-1) + n

T(n) =[T(n-3) + (n-2) ] + (n-1) + n

T(n) = T(n-3) +(n-2) +(n-1) + n

…………………………………………………

T(n) = T(n-k) + (n-(k-1)) + (n- (k-2)) +…..+ (n-(k-k))

T(n) =T(n-k) + (n-k+1) +(n-k+2) +……+n

n-k=0 => n=k

T(n) = T(0) + 1+2+….+n

n∗(n+1)
T(n) =1 +
2
n2 n
T(n) = 1 + +
2 2
T(n) = O(n2)

Eg 3:

T(n) = 1 if n=1

= T(n-1) * n if n>1

Sol:

You might also like