0% found this document useful (0 votes)
32 views

Recurrence Relation

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)
32 views

Recurrence Relation

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/ 5

Recurrence relation

The running time for a recursive algorithm is most easily expressed by a recursive expression
because the total time for the recursive algorithm includes the time to run the recursive call(s).
A recurrence relation defines a function by means of an expression that includes one or more
(smaller) instances of itself. A classic example is the recursive definition for the factorial
function:

n!=(n−1)!⋅n for n>1;1!=0!=1.𝑛!=(𝑛−1)!⋅𝑛 for 𝑛>1;1!=0!=1.

Another standard example of a recurrence is the Fibonacci sequence:

Fib(n)=Fib(n−1)+Fib(n−2) for n>2;Fib(1)=Fib(2)=1.Fib(𝑛)=Fib(𝑛−1)+Fib(𝑛−2) for 𝑛>2;Fib(


1)=Fib(2)=1.

From this definition, the first seven numbers of the Fibonacci sequence are

1,1,2,3,5,8, and 13.1,1,2,3,5,8, and 13.

Notice that this definition contains two parts: the general definition for Fib(n)Fib(𝑛) and the
base cases for Fib(1)Fib(1) and Fib(2)Fib(2). Likewise, the definition for factorial contains a
recursive part and base cases.

Recurrence relations are often used to model the cost of recursive functions. For example, the
number of multiplications required by a recursive version of the factorial function for an input
of size n𝑛 will be zero when n=0𝑛=0 or n=1𝑛=1 (the base cases), and it will be one plus the
cost of calling fact on a value of n−1𝑛−1. This can be defined using the following recurrence:

T(n)=T(n−1)+1 for n>1;T(0)=T(1)=0.

Substitution Method
The substitution method for solving recurrences is famously described using two steps:

1. Guess the form of the solution.

2. Use induction to show that the guess is valid.

Example: Determine a tight asymptotic lower bound for the following recurrence:

𝑇(𝑛)=4𝑇(𝑛/2)+𝑛2
T(n)=Ω(cn2lg(n))

Example:

Recursion Tree method


In this method, a recurrence relation is converted into recursive trees. Each node represents
the cost incurred at various levels of recursion. To find the total cost, costs of all levels are
summed up.
The Master Method
Suppose you have a recurrence of the form
T(n) = aT(n/b) + f(n),
where a and b are arbitrary constants and f is some function of n.
Case 1: f(n) is O(nlogba − ε). Since the leaves grow faster than f, asymptotically all of the
work is done at the leaves, so T(n) is Θ(nlogb a).
Case 2: f(n) is Θ(nlogba). The leaves grow at the same rate as f, so the same order of work
is done at every level of the tree. The tree has O(log n) levels, times the work done on one
level, yielding T(n) is Θ(nlogb a log n).
Case 3: f(n) is Ω(nlogba + ε). In this case f grows faster than the number of leaves, which
means that asymptotically the total amount of work is dominated by the work done at the
root node. For the upper bound, we also need an extra smoothness condition on f in this
case, namely that af(n/b) ≤ cf(n) for some constant c < 1 and large n. In this
case T(n) is Θ(f(n)).

You might also like