Recurrence Relation
Definition: A recurrence relation calls itself.Â
Example – Fibonacci series
1Â Â 1Â Â 2Â Â 3Â Â 5Â Â 8Â Â 13Â Â 21Â Â 34Â Â 55 . . .Â
In this, sequence is made by the addition of the last two terms
1 + 1 = 2,  1 + 2 = 3,  2 + 3 = 5…
Â
Recurrence function   f(n + 1) = f(n) + f(n – 1)
Â

Â
Recurrence –
It is a mathematical function to approximate the recursion function in the context of time complexity and the number of comparisons.Â
Let T(n) is a mathematical function to approximate recursive function.Â
Â
Rules of recurrence –Â
1. If the given instance of the problem is small or simple enough, just solve it.
2. Otherwise, reduce the problem to one or more, simpler instances of the same problem.
Â

Â
Algorithms of Recurrence Relation
Algorithm 1
f1(int n)
{
 if (n <= 1 )
   return;
 f1(n-1);
}
Recurrence function –Â
T(1) = Θ(1)
T(n) = T(n – 1) + Θ(1)          Â
T(n – 1) is compiling time and Θ(1) is running time.
Trial –Â
If n = 1, then T(1) = Θ(1)
If n = 2, then we find f(1)
Algorithm 2
f2(int n)
{
 if (n <= 1)
   return;
 f2(n/2);
}
Recurrence function –Â
T(1) = Θ(1)
T(n) = T(n/2) + Θ(1)          Â
T(n/2) is compiling time and Θ(1) is running time.
Test Yourself
Ques (1)
f(int n)
{
 if(n <= 1)
   return;
 f(n – 1);
 f(n – 1);
}
Â
Recurrence function –Â
Â
T(1) = Θ(1)
T(n) = 2T(n – 1) + Θ(1)        T(n – 1) is compiling time and Θ(1) is running time.
Â
Ques (2)
f(int n)
{
 if(n <= 1)
   return;
 f3(n/2);
 f3(n/2);
}
Â
Recurrence function –Â
Â
T(1) = Θ(1)
T(n) = 2T(n/2) + Θ(1)          T(n/2) is compiling time and Θ(1) is running time.
Ques (3)
f(int n)
{
 int i, s = 0;
 if(n <= 1)
   return;
 for(i = 1; i <= n; i++)
 {
   s = s + n;
 }
 return f(n/2) + f(n/2) + s;
}
Â
Recurrence function –Â
Â
T(1) = Θ(1)
Â
T(n) = 2T(n/2) + Θ(n)  [ s is continuously adding n times so that’s why Θ(n)].