0% found this document useful (0 votes)
22 views3 pages

Ada 2

Uploaded by

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

Ada 2

Uploaded by

Sunshine Ratrey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

8. What is Recurrence Relation?

Answer-

 A recurrence is an equation or inequality that describes a function in terms of its values on


smaller inputs.
 It helps in finding the subsequent term (next term) dependent upon the preceding term
(previous term).
 If we know the previous term in a given series, then we can easily determine the next term.

Example-

 Fibonacci numbers is defined by the recurrence relation

Fn = Fn-1 + Fn-2

There are four methods for solving Recurrence:

1. Iteration Method (Back Substitution Method)


2. Master Method
3. Recursion Tree Method
4. Substitution Method
---------------------------------------------------------------------------------------------------------------------------

Iteration Method (Back Substitution Method):-


 The iteration method is a "brute force" method of solving a recurrence relation.
 The general idea is to iteratively substitute the value of the recurrent part of the equation until
a pattern (usually a summation) is noticed, at which point the summation can be used to
evaluate the recurrence.

Example-1-

1 𝑖𝑓 𝑛 = 1
𝑇(𝑛) =
𝑇(𝑛 − 1) + 𝑛 𝑖𝑓 𝑛 > 1

Solution-

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

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

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


Substituting equation (3) in equation (2)

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

Substituting equation (2) in equation (1)

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

Repeating k times

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

Putting n-k = 1

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

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

Given that, when n=1 then T(n) = 1

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

Hence 1 + 2 + 3 + …………… + (n-2) + (n-1) + n = n(n+1)/2

T(n) = n(n+1)/2 = (n2 + n)/2

T(n) = = (n2 + n)/2

T(n) = O(n2)

Example-2-

2𝑇(𝑛 − 1) − 1 𝑖𝑓 𝑛 > 0
𝑇(𝑛) =
1 𝑂𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒

Solution-

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

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

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


Substituting equation (3) in equation (2)

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

Substituting equation (2) in equation (1)

T(n) = 2[2{2T(n-3)-1}-1]-1

T(n) = 22{2T(n-3)-1}-2-1

T(n) = 23T(n-3)-22-2-1

Repeating k times

T(n) = 2kT(n-k)- 2k-1 - 2k-2 - ……………………… -22-2-1

Putting n = k

T(n) = 2n T(0)- 2n-1 – 2n-2 - ……………………… -22-2-1

Given that, other than n > 0 gives T(n) = 1

T(n) = 2n - 2n-1 – 2n-2 - ……………………… -22-2-1

T(n) = 2n – (2n-1 + 2n-2 + ……………………… +22+2+1)

Hence 2n-1 + 2n-2 + ……………………… +22+2+1 = (2n - 1)/ 2-1 = (2n - 1)

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

T(n) = 1

T(n) = O(1)

You might also like