Recursive Relation $T(n)=T(n-1)+1$

4.7k Views Asked by At

I have wrote a recursive code of the type:

function(n){
   if n==1:
     return
   else{
   do something
   function(n-1)
}

Now I am trying to analyze the complexity

I came to $T(n)=T(n-1)+1$ but how do I solve this kind of recursive relation? master theorem can not be used, I vaguely remember something like:

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

So it is of the kind $$T(n)=T(n-k)+1$$ and then we set $m=n-k$

But I do not remember how to proceed.

2

There are 2 best solutions below

1
On BEST ANSWER

Note this $$T(n) - T(0) = \sum_{k=1}^n T(k) - T(k-1).$$

3
On

By expanding the recursive equation, you can found $T(n) = \Theta(n)$ (by induction).